diff --git a/sentry-test-support/api/sentry-test-support.api b/sentry-test-support/api/sentry-test-support.api index 8bfaaeefef1..1d8ae671216 100644 --- a/sentry-test-support/api/sentry-test-support.api +++ b/sentry-test-support/api/sentry-test-support.api @@ -55,6 +55,16 @@ public final class io/sentry/test/MocksKt { public static synthetic fun createTestScopes$default (Lio/sentry/SentryOptions;ZLio/sentry/IScope;Lio/sentry/IScope;Lio/sentry/IScope;ILjava/lang/Object;)Lio/sentry/Scopes; } +public final class io/sentry/test/NonOverridableNoOpSentryExecutorService : io/sentry/ISentryExecutorService { + public fun ()V + public fun close (J)V + public fun isClosed ()Z + public fun prewarm ()V + public fun schedule (Ljava/lang/Runnable;J)Ljava/util/concurrent/Future; + public fun submit (Ljava/lang/Runnable;)Ljava/util/concurrent/Future; + public fun submit (Ljava/util/concurrent/Callable;)Ljava/util/concurrent/Future; +} + public final class io/sentry/test/ReflectionKt { public static final fun collectInterfaceHierarchy (Ljava/lang/Class;)Ljava/util/List; public static final fun containsMethod (Ljava/lang/Class;Ljava/lang/String;Ljava/lang/Class;)Z diff --git a/sentry-test-support/src/main/kotlin/io/sentry/test/Mocks.kt b/sentry-test-support/src/main/kotlin/io/sentry/test/Mocks.kt index 09d5d181ec4..da69b7cf330 100644 --- a/sentry-test-support/src/main/kotlin/io/sentry/test/Mocks.kt +++ b/sentry-test-support/src/main/kotlin/io/sentry/test/Mocks.kt @@ -79,6 +79,21 @@ class DeferredExecutorService : ISentryExecutorService { fun hasScheduledRunnables(): Boolean = scheduledRunnables.isNotEmpty() } +class NonOverridableNoOpSentryExecutorService : ISentryExecutorService { + override fun submit(runnable: Runnable): Future<*> = FutureTask { null } + + override fun submit(callable: Callable): Future = FutureTask { null } + + override fun schedule(runnable: Runnable, delayMillis: Long): Future<*> = + FutureTask { null } + + override fun close(timeoutMillis: Long) {} + + override fun isClosed(): Boolean = false + + override fun prewarm() = Unit +} + fun createSentryClientMock(enabled: Boolean = true) = mock().also { val isEnabled = AtomicBoolean(enabled) diff --git a/sentry/src/test/java/io/sentry/SentryTest.kt b/sentry/src/test/java/io/sentry/SentryTest.kt index c94375735d2..72febe35665 100644 --- a/sentry/src/test/java/io/sentry/SentryTest.kt +++ b/sentry/src/test/java/io/sentry/SentryTest.kt @@ -17,6 +17,7 @@ import io.sentry.protocol.SdkVersion import io.sentry.protocol.SentryId import io.sentry.protocol.SentryThread import io.sentry.test.ImmediateExecutorService +import io.sentry.test.NonOverridableNoOpSentryExecutorService import io.sentry.test.createSentryClientMock import io.sentry.test.initForTest import io.sentry.test.injectForField @@ -1217,7 +1218,7 @@ class SentryTest { it.profilesSampleRate = 1.0 it.tracesSampler = mockSampleTracer it.profilesSampler = mockProfilesSampler - it.executorService = NoOpSentryExecutorService.getInstance() + it.executorService = NonOverridableNoOpSentryExecutorService() it.cacheDirPath = getTempPath() } // Samplers are called with isForNextAppStart flag set to true @@ -1236,7 +1237,7 @@ class SentryTest { it.profilesSampleRate = 1.0 it.tracesSampler = mockSampleTracer it.profilesSampler = mockProfilesSampler - it.executorService = NoOpSentryExecutorService.getInstance() + it.executorService = NonOverridableNoOpSentryExecutorService() it.cacheDirPath = null } // Samplers are called with isForNextAppStart flag set to true