From 55ba50e53ce37ab52a2310fd975b60369fe5643a Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 18 Dec 2024 11:47:00 +0100 Subject: [PATCH] Speed up tests by reducing shutdownTimeout --- .../android/core/InternalSentrySdkTest.kt | 2 +- .../sentry/android/core/SentryAndroidTest.kt | 30 +++- .../android/core/SentryLogcatAdapterTest.kt | 4 +- .../core/SessionTrackingIntegrationTest.kt | 2 +- .../build.gradle.kts | 1 + .../android/benchmark/SentryBenchmarkTest.kt | 13 +- .../io/sentry/uitest/android/BaseUiTest.kt | 12 +- .../replay/AnrWithReplayIntegrationTest.kt | 11 +- .../kotlin/io/sentry/jul/SentryHandlerTest.kt | 3 +- .../io/sentry/kotlin/SentryContextTest.kt | 3 +- .../io/sentry/log4j2/SentryAppenderTest.kt | 3 +- .../io/sentry/logback/SentryAppenderTest.kt | 3 +- .../spring/jakarta/SentryTaskDecoratorTest.kt | 3 +- .../jakarta/webflux/SentryScheduleHookTest.kt | 3 +- .../webflux/SentryWebfluxIntegrationTest.kt | 3 +- .../sentry/spring/SentryTaskDecoratorTest.kt | 3 +- .../spring/webflux/SentryScheduleHookTest.kt | 3 +- .../webflux/SentryWebfluxIntegrationTest.kt | 3 +- .../api/sentry-test-support.api | 9 ++ .../src/main/kotlin/io/sentry/test/Init.kt | 39 +++++ sentry/src/test/java/io/sentry/ScopesTest.kt | 3 +- sentry/src/test/java/io/sentry/SentryTest.kt | 147 +++++++++--------- .../test/java/io/sentry/SentryWrapperTest.kt | 9 +- .../ClientReportMultiThreadingTest.kt | 3 +- .../sentry/clientreport/ClientReportTest.kt | 3 +- 25 files changed, 215 insertions(+), 103 deletions(-) create mode 100644 sentry-test-support/src/main/kotlin/io/sentry/test/Init.kt diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/InternalSentrySdkTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/InternalSentrySdkTest.kt index 5f63f39cae8..01b9845a9fe 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/InternalSentrySdkTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/InternalSentrySdkTest.kt @@ -55,7 +55,7 @@ class InternalSentrySdkTest { lateinit var options: SentryOptions fun init(context: Context) { - SentryAndroid.init(context) { options -> + initForTest(context) { options -> this@Fixture.options = options options.dsn = "https://key@host/proj" options.setTransportFactory { _, _ -> diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt index 6fe39bb9d8b..c7c6f8bbaed 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt @@ -15,6 +15,7 @@ import io.sentry.Hint import io.sentry.ILogger import io.sentry.ISentryClient import io.sentry.Sentry +import io.sentry.Sentry.OptionsConfiguration import io.sentry.SentryEnvelope import io.sentry.SentryLevel import io.sentry.SentryLevel.DEBUG @@ -40,6 +41,8 @@ import io.sentry.cache.PersistingScopeObserver import io.sentry.cache.PersistingScopeObserver.BREADCRUMBS_FILENAME import io.sentry.cache.PersistingScopeObserver.SCOPE_CACHE import io.sentry.cache.PersistingScopeObserver.TRANSACTION_FILENAME +import io.sentry.test.applyTestOptions +import io.sentry.test.initForTest import io.sentry.transport.NoOpEnvelopeCache import io.sentry.util.StringUtils import org.awaitility.kotlin.await @@ -100,9 +103,9 @@ class SentryAndroidTest { } val mockContext = context ?: ContextUtilsTestHelper.mockMetaData(metaData = metadata) when { - logger != null -> SentryAndroid.init(mockContext, logger) - options != null -> SentryAndroid.init(mockContext, options) - else -> SentryAndroid.init(mockContext) + logger != null -> initForTest(mockContext, logger) + options != null -> initForTest(mockContext, options) + else -> initForTest(mockContext) } } @@ -290,7 +293,7 @@ class SentryAndroidTest { val mockContext = ContextUtilsTestHelper.createMockContext(true) val cacheDirPath = Files.createTempDirectory("new_cache").absolutePathString() - SentryAndroid.init(mockContext) { + initForTest(mockContext) { it.dsn = "https://key@sentry.io/123" it.cacheDirPath = cacheDirPath options = it @@ -354,7 +357,7 @@ class SentryAndroidTest { @Test fun `When initializing Sentry a callback is added to application by appStartMetrics`() { val mockContext = ContextUtilsTestHelper.createMockContext(true) - SentryAndroid.init(mockContext) { + initForTest(mockContext) { it.dsn = "https://key@sentry.io/123" } verify(mockContext.applicationContext as Application).registerActivityLifecycleCallbacks(eq(AppStartMetrics.getInstance())) @@ -368,7 +371,7 @@ class SentryAndroidTest { Mockito.mockStatic(ContextUtils::class.java, Mockito.CALLS_REAL_METHODS).use { mockedContextUtils -> mockedContextUtils.`when` { ContextUtils.isForegroundImportance() } .thenReturn(inForeground) - SentryAndroid.init(context) { options -> + initForTest(context) { options -> options.release = "prod" options.dsn = "https://key@sentry.io/123" options.isEnableAutoSessionTracking = true @@ -558,3 +561,18 @@ class SentryAndroidTest { override fun discard(envelope: SentryEnvelope) = Unit } } + +fun initForTest(context: Context, optionsConfiguration: OptionsConfiguration) { + SentryAndroid.init(context) { + applyTestOptions(it) + optionsConfiguration.configure(it) + } +} + +fun initForTest(context: Context, logger: ILogger) { + SentryAndroid.init(context, logger) +} + +fun initForTest(context: Context) { + SentryAndroid.init(context) +} diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/SentryLogcatAdapterTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/SentryLogcatAdapterTest.kt index 1939e7ed801..857cc658c20 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/SentryLogcatAdapterTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/SentryLogcatAdapterTest.kt @@ -30,8 +30,8 @@ class SentryLogcatAdapterTest { } val mockContext = ContextUtilsTestHelper.mockMetaData(metaData = metadata) when { - options != null -> SentryAndroid.init(mockContext, options) - else -> SentryAndroid.init(mockContext) + options != null -> initForTest(mockContext, options) + else -> initForTest(mockContext) } } } diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/SessionTrackingIntegrationTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/SessionTrackingIntegrationTest.kt index e392d238ab8..f6fb464bf3b 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/SessionTrackingIntegrationTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/SessionTrackingIntegrationTest.kt @@ -44,7 +44,7 @@ class SessionTrackingIntegrationTest { @Test fun `session tracking works properly with multiple backgrounds and foregrounds`() { lateinit var options: SentryAndroidOptions - SentryAndroid.init(context) { + initForTest(context) { it.dsn = "https://key@sentry.io/proj" it.release = "io.sentry.samples@2.3.0" it.environment = "production" diff --git a/sentry-android-integration-tests/sentry-uitest-android-benchmark/build.gradle.kts b/sentry-android-integration-tests/sentry-uitest-android-benchmark/build.gradle.kts index 9f9fd1b3d67..b15e7626dc6 100644 --- a/sentry-android-integration-tests/sentry-uitest-android-benchmark/build.gradle.kts +++ b/sentry-android-integration-tests/sentry-uitest-android-benchmark/build.gradle.kts @@ -99,6 +99,7 @@ dependencies { errorprone(Config.CompileOnly.errorprone) errorprone(Config.CompileOnly.errorProneNullAway) + androidTestImplementation(projects.sentryTestSupport) androidTestImplementation(Config.TestLibs.kotlinTestJunit) androidTestImplementation(Config.TestLibs.espressoCore) androidTestImplementation(Config.TestLibs.androidxTestCoreKtx) diff --git a/sentry-android-integration-tests/sentry-uitest-android-benchmark/src/androidTest/java/io/sentry/uitest/android/benchmark/SentryBenchmarkTest.kt b/sentry-android-integration-tests/sentry-uitest-android-benchmark/src/androidTest/java/io/sentry/uitest/android/benchmark/SentryBenchmarkTest.kt index 110f9214b51..ca6ed2ded2d 100644 --- a/sentry-android-integration-tests/sentry-uitest-android-benchmark/src/androidTest/java/io/sentry/uitest/android/benchmark/SentryBenchmarkTest.kt +++ b/sentry-android-integration-tests/sentry-uitest-android-benchmark/src/androidTest/java/io/sentry/uitest/android/benchmark/SentryBenchmarkTest.kt @@ -1,5 +1,6 @@ package io.sentry.uitest.android.benchmark +import android.content.Context import android.os.Bundle import androidx.lifecycle.Lifecycle import androidx.test.core.app.launchActivity @@ -12,8 +13,11 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.runner.AndroidJUnitRunner import io.sentry.ITransaction import io.sentry.Sentry +import io.sentry.Sentry.OptionsConfiguration import io.sentry.SentryOptions import io.sentry.android.core.SentryAndroid +import io.sentry.android.core.SentryAndroidOptions +import io.sentry.test.applyTestOptions import io.sentry.uitest.android.benchmark.util.BenchmarkOperation import org.junit.runner.RunWith import kotlin.test.AfterTest @@ -62,7 +66,7 @@ class SentryBenchmarkTest : BaseBenchmarkTest() { choreographer, before = { runner.runOnMainSync { - SentryAndroid.init(context) { options: SentryOptions -> + initForTest(context) { options: SentryOptions -> options.dsn = "https://key@uri/1234567" options.tracesSampleRate = 1.0 options.profilesSampleRate = 1.0 @@ -127,3 +131,10 @@ class SentryBenchmarkTest : BaseBenchmarkTest() { } } } + +fun initForTest(context: Context, optionsConfiguration: OptionsConfiguration) { + SentryAndroid.init(context) { + applyTestOptions(it) + optionsConfiguration.configure(it) + } +} diff --git a/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/BaseUiTest.kt b/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/BaseUiTest.kt index bfac0c3b5f2..f1ed40eeff7 100644 --- a/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/BaseUiTest.kt +++ b/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/BaseUiTest.kt @@ -9,8 +9,11 @@ import androidx.test.espresso.idling.CountingIdlingResource import androidx.test.platform.app.InstrumentationRegistry import androidx.test.runner.AndroidJUnitRunner import io.sentry.Sentry +import io.sentry.Sentry.OptionsConfiguration import io.sentry.android.core.SentryAndroid import io.sentry.android.core.SentryAndroidOptions +import io.sentry.test.applyTestOptions +import io.sentry.test.initForTest import io.sentry.uitest.android.mockservers.MockRelay import java.io.FileInputStream import java.util.concurrent.TimeUnit @@ -84,7 +87,7 @@ abstract class BaseUiTest { if (relayWaitForRequests) { IdlingRegistry.getInstance().register(relayIdlingResource) } - SentryAndroid.init(context) { + initForTest(context) { it.dsn = mockDsn it.isDebug = true // We don't use test orchestrator, due to problems with Saucelabs. @@ -111,3 +114,10 @@ fun classExists(className: String): Boolean { } return false } + +fun initForTest(context: Context, optionsConfiguration: OptionsConfiguration) { + SentryAndroid.init(context) { + applyTestOptions(it) + optionsConfiguration.configure(it) + } +} diff --git a/sentry-android-replay/src/test/java/io/sentry/android/replay/AnrWithReplayIntegrationTest.kt b/sentry-android-replay/src/test/java/io/sentry/android/replay/AnrWithReplayIntegrationTest.kt index a050bd885f9..5aa210f5890 100644 --- a/sentry-android-replay/src/test/java/io/sentry/android/replay/AnrWithReplayIntegrationTest.kt +++ b/sentry-android-replay/src/test/java/io/sentry/android/replay/AnrWithReplayIntegrationTest.kt @@ -16,6 +16,7 @@ import io.sentry.SentryReplayEvent import io.sentry.SentryReplayEvent.ReplayType import io.sentry.SystemOutLogger import io.sentry.android.core.SentryAndroid +import io.sentry.android.core.SentryAndroidOptions import io.sentry.android.core.performance.AppStartMetrics import io.sentry.android.replay.ReplayCache.Companion.ONGOING_SEGMENT import io.sentry.android.replay.ReplayCache.Companion.SEGMENT_KEY_BIT_RATE @@ -32,6 +33,7 @@ import io.sentry.protocol.Contexts import io.sentry.protocol.SentryId import io.sentry.rrweb.RRWebMetaEvent import io.sentry.rrweb.RRWebVideoEvent +import io.sentry.test.applyTestOptions import org.awaitility.kotlin.await import org.awaitility.kotlin.withAlias import org.junit.Rule @@ -146,7 +148,7 @@ class AnrWithReplayIntegrationTest { val replayId1 = SentryId() val replayId2 = SentryId() - SentryAndroid.init(context) { + initForTest(context) { it.dsn = "https://key@sentry.io/123" it.cacheDirPath = cacheDir it.isDebug = true @@ -216,3 +218,10 @@ class AnrWithReplayIntegrationTest { .untilTrue(asserted) } } + +fun initForTest(context: Context, optionsConfiguration: Sentry.OptionsConfiguration) { + SentryAndroid.init(context) { + applyTestOptions(it) + optionsConfiguration.configure(it) + } +} diff --git a/sentry-jul/src/test/kotlin/io/sentry/jul/SentryHandlerTest.kt b/sentry-jul/src/test/kotlin/io/sentry/jul/SentryHandlerTest.kt index ad53182b803..5b7048884d3 100644 --- a/sentry-jul/src/test/kotlin/io/sentry/jul/SentryHandlerTest.kt +++ b/sentry-jul/src/test/kotlin/io/sentry/jul/SentryHandlerTest.kt @@ -5,6 +5,7 @@ import io.sentry.Sentry import io.sentry.SentryLevel import io.sentry.SentryOptions import io.sentry.checkEvent +import io.sentry.test.initForTest import io.sentry.transport.ITransport import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.mock @@ -60,7 +61,7 @@ class SentryHandlerTest { @Test fun `does not initialize Sentry if Sentry is already enabled with higher prio`() { val transport = mock() - Sentry.init { + initForTest { it.dsn = "http://key@localhost/proj" it.environment = "manual-environment" it.setTransportFactory { _, _ -> transport } diff --git a/sentry-kotlin-extensions/src/test/java/io/sentry/kotlin/SentryContextTest.kt b/sentry-kotlin-extensions/src/test/java/io/sentry/kotlin/SentryContextTest.kt index 9cffd744d85..086879f7d15 100644 --- a/sentry-kotlin-extensions/src/test/java/io/sentry/kotlin/SentryContextTest.kt +++ b/sentry-kotlin-extensions/src/test/java/io/sentry/kotlin/SentryContextTest.kt @@ -2,6 +2,7 @@ package io.sentry.kotlin import io.sentry.ScopeType import io.sentry.Sentry +import io.sentry.test.initForTest import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.joinAll import kotlinx.coroutines.launch @@ -22,7 +23,7 @@ class SentryContextTest { @BeforeTest fun init() { - Sentry.init("https://key@sentry.io/123") + initForTest("https://key@sentry.io/123") } @AfterTest diff --git a/sentry-log4j2/src/test/kotlin/io/sentry/log4j2/SentryAppenderTest.kt b/sentry-log4j2/src/test/kotlin/io/sentry/log4j2/SentryAppenderTest.kt index 80405f1b4c8..f19e62ba572 100644 --- a/sentry-log4j2/src/test/kotlin/io/sentry/log4j2/SentryAppenderTest.kt +++ b/sentry-log4j2/src/test/kotlin/io/sentry/log4j2/SentryAppenderTest.kt @@ -6,6 +6,7 @@ import io.sentry.ScopesAdapter import io.sentry.Sentry import io.sentry.SentryLevel import io.sentry.checkEvent +import io.sentry.test.initForTest import io.sentry.transport.ITransport import org.apache.logging.log4j.Level import org.apache.logging.log4j.LogManager @@ -84,7 +85,7 @@ class SentryAppenderTest { @Test fun `does not initialize Sentry if Sentry is already enabled with higher prio`() { - Sentry.init { + initForTest { it.dsn = "http://key@localhost/proj" it.environment = "manual-environment" it.setTransportFactory(fixture.transportFactory) diff --git a/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt b/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt index abb4a5bd616..526220d333b 100644 --- a/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt +++ b/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt @@ -13,6 +13,7 @@ import io.sentry.Sentry import io.sentry.SentryLevel import io.sentry.SentryOptions import io.sentry.checkEvent +import io.sentry.test.initForTest import io.sentry.transport.ITransport import org.mockito.kotlin.any import org.mockito.kotlin.anyOrNull @@ -96,7 +97,7 @@ class SentryAppenderTest { it.setTag("only-present-if-logger-init-was-run", "another-value") } ) - Sentry.init { + initForTest { it.dsn = "http://key@localhost/proj" it.environment = "manual-environment" it.setTransportFactory(fixture.transportFactory) diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryTaskDecoratorTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryTaskDecoratorTest.kt index d44e64f78d6..7d8bc4ed812 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryTaskDecoratorTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryTaskDecoratorTest.kt @@ -1,6 +1,7 @@ package io.sentry.spring.jakarta import io.sentry.Sentry +import io.sentry.test.initForTest import java.util.concurrent.ExecutorService import java.util.concurrent.Executors import kotlin.test.AfterTest @@ -26,7 +27,7 @@ class SentryTaskDecoratorTest { @Test fun `scopes is reset to its state within the thread after decoration is done`() { - Sentry.init { + initForTest { it.dsn = dsn } diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryScheduleHookTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryScheduleHookTest.kt index 4b540da1aab..6240ae96f78 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryScheduleHookTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryScheduleHookTest.kt @@ -1,6 +1,7 @@ package io.sentry.spring.jakarta.webflux import io.sentry.Sentry +import io.sentry.test.initForTest import java.util.concurrent.ExecutorService import java.util.concurrent.Executors import kotlin.test.AfterTest @@ -27,7 +28,7 @@ class SentryScheduleHookTest { @Test fun `scopes is reset to its state within the thread after hook is done`() { - Sentry.init { + initForTest { it.dsn = dsn } diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryWebfluxIntegrationTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryWebfluxIntegrationTest.kt index 742f9c907b5..a6a6deee2eb 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryWebfluxIntegrationTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryWebfluxIntegrationTest.kt @@ -6,6 +6,7 @@ import io.sentry.ScopesAdapter import io.sentry.Sentry import io.sentry.checkEvent import io.sentry.checkTransaction +import io.sentry.test.initForTest import io.sentry.transport.ITransport import org.assertj.core.api.Assertions.assertThat import org.awaitility.kotlin.await @@ -175,7 +176,7 @@ open class App { @Bean open fun sentryInitializer(transportFactory: ITransportFactory) = ApplicationRunner { - Sentry.init { + initForTest { it.dsn = "http://key@localhost/proj" it.setDebug(true) it.setTransportFactory(transportFactory) diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/SentryTaskDecoratorTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/SentryTaskDecoratorTest.kt index 4bbce919eb6..cf0526d4166 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/SentryTaskDecoratorTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/SentryTaskDecoratorTest.kt @@ -1,6 +1,7 @@ package io.sentry.spring import io.sentry.Sentry +import io.sentry.test.initForTest import java.util.concurrent.ExecutorService import java.util.concurrent.Executors import kotlin.test.AfterTest @@ -26,7 +27,7 @@ class SentryTaskDecoratorTest { @Test fun `scopes is reset to its state within the thread after decoration is done`() { - Sentry.init { + initForTest { it.dsn = dsn } diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryScheduleHookTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryScheduleHookTest.kt index 88c33c3695f..adfc4a2baa8 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryScheduleHookTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryScheduleHookTest.kt @@ -1,6 +1,7 @@ package io.sentry.spring.webflux import io.sentry.Sentry +import io.sentry.test.initForTest import java.util.concurrent.ExecutorService import java.util.concurrent.Executors import kotlin.test.AfterTest @@ -27,7 +28,7 @@ class SentryScheduleHookTest { @Test fun `scopes is reset to its state within the thread after hook is done`() { - Sentry.init { + initForTest { it.dsn = dsn } diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryWebfluxIntegrationTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryWebfluxIntegrationTest.kt index 5a2ebb107cc..b61a29e6462 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryWebfluxIntegrationTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryWebfluxIntegrationTest.kt @@ -6,6 +6,7 @@ import io.sentry.ScopesAdapter import io.sentry.Sentry import io.sentry.checkEvent import io.sentry.checkTransaction +import io.sentry.test.initForTest import io.sentry.transport.ITransport import org.assertj.core.api.Assertions.assertThat import org.awaitility.kotlin.await @@ -175,7 +176,7 @@ open class App { @Bean open fun sentryInitializer(transportFactory: ITransportFactory) = ApplicationRunner { - Sentry.init { + initForTest { it.dsn = "http://key@localhost/proj" it.setDebug(true) it.setTransportFactory(transportFactory) diff --git a/sentry-test-support/api/sentry-test-support.api b/sentry-test-support/api/sentry-test-support.api index 8ef2e78743f..c75fb062b0a 100644 --- a/sentry-test-support/api/sentry-test-support.api +++ b/sentry-test-support/api/sentry-test-support.api @@ -32,6 +32,15 @@ public final class io/sentry/test/ImmediateExecutorService : io/sentry/ISentryEx public fun submit (Ljava/util/concurrent/Callable;)Ljava/util/concurrent/Future; } +public final class io/sentry/test/InitKt { + public static final fun applyTestOptions (Lio/sentry/SentryOptions;)V + public static final fun initForTest ()V + public static final fun initForTest (Lio/sentry/Sentry$OptionsConfiguration;)V + public static final fun initForTest (Lio/sentry/Sentry$OptionsConfiguration;Z)V + public static final fun initForTest (Lio/sentry/SentryOptions;)V + public static final fun initForTest (Ljava/lang/String;)V +} + public final class io/sentry/test/MocksKt { public static final fun createSentryClientMock (Z)Lio/sentry/ISentryClient; public static synthetic fun createSentryClientMock$default (ZILjava/lang/Object;)Lio/sentry/ISentryClient; diff --git a/sentry-test-support/src/main/kotlin/io/sentry/test/Init.kt b/sentry-test-support/src/main/kotlin/io/sentry/test/Init.kt new file mode 100644 index 00000000000..67006a0920e --- /dev/null +++ b/sentry-test-support/src/main/kotlin/io/sentry/test/Init.kt @@ -0,0 +1,39 @@ +package io.sentry.test + +import io.sentry.Sentry +import io.sentry.Sentry.OptionsConfiguration +import io.sentry.SentryOptions + +fun initForTest(optionsConfiguration: OptionsConfiguration) { + Sentry.init { + applyTestOptions(it) + optionsConfiguration.configure(it) + } +} + +fun initForTest(optionsConfiguration: OptionsConfiguration, globalHubMode: Boolean) { + Sentry.init({ + applyTestOptions(it) + optionsConfiguration.configure(it) + }, globalHubMode) +} + +fun initForTest(dsn: String) { + Sentry.init { + applyTestOptions(it) + it.dsn = dsn + } +} + +fun initForTest(options: SentryOptions) { + applyTestOptions(options) + Sentry.init(options) +} + +fun initForTest() { + Sentry.init() +} + +fun applyTestOptions(options: SentryOptions) { + options.shutdownTimeoutMillis = 0 +} diff --git a/sentry/src/test/java/io/sentry/ScopesTest.kt b/sentry/src/test/java/io/sentry/ScopesTest.kt index f0e9833cb88..c12bc9371b1 100644 --- a/sentry/src/test/java/io/sentry/ScopesTest.kt +++ b/sentry/src/test/java/io/sentry/ScopesTest.kt @@ -14,6 +14,7 @@ import io.sentry.test.DeferredExecutorService import io.sentry.test.callMethod import io.sentry.test.createSentryClientMock import io.sentry.test.createTestScopes +import io.sentry.test.initForTest import io.sentry.util.HintUtils import io.sentry.util.StringUtils import junit.framework.TestCase.assertSame @@ -964,7 +965,7 @@ class ScopesTest { var options: SentryOptions? = null // init main scopes and make it enabled - Sentry.init { + initForTest { it.addIntegration(mock) it.dsn = "https://key@sentry.io/proj" it.cacheDirPath = file.absolutePath diff --git a/sentry/src/test/java/io/sentry/SentryTest.kt b/sentry/src/test/java/io/sentry/SentryTest.kt index 5c707a98936..f5a6ad16c1a 100644 --- a/sentry/src/test/java/io/sentry/SentryTest.kt +++ b/sentry/src/test/java/io/sentry/SentryTest.kt @@ -16,6 +16,7 @@ import io.sentry.protocol.SentryId import io.sentry.protocol.SentryThread import io.sentry.test.ImmediateExecutorService import io.sentry.test.createSentryClientMock +import io.sentry.test.initForTest import io.sentry.test.injectForField import io.sentry.util.PlatformTestManipulator import io.sentry.util.thread.IThreadChecker @@ -71,11 +72,11 @@ class SentryTest { @Test fun `init multiple times calls scopes close with isRestarting true`() { val scopes = mock() - Sentry.init { + initForTest { it.dsn = dsn } Sentry.setCurrentScopes(scopes) - Sentry.init { + initForTest { it.dsn = dsn } verify(scopes).close(eq(true)) @@ -85,13 +86,13 @@ class SentryTest { fun `init multiple times calls close on previous options not new`() { val profiler1 = mock() val profiler2 = mock() - Sentry.init { + initForTest { it.dsn = dsn it.setTransactionProfiler(profiler1) } verify(profiler1, never()).close() - Sentry.init { + initForTest { it.dsn = dsn it.setTransactionProfiler(profiler2) } @@ -106,13 +107,13 @@ class SentryTest { fun `init multiple times calls close on previous integrations not new`() { val integration1 = mock() val integration2 = mock() - Sentry.init { + initForTest { it.dsn = dsn it.addIntegration(integration1) } verify(integration1, never()).close() - Sentry.init { + initForTest { it.dsn = dsn it.addIntegration(integration2) } @@ -131,11 +132,11 @@ class SentryTest { whenever(scopes.close()).then { Sentry.getGlobalScope().client.close() } whenever(scopes.close(anyOrNull())).then { Sentry.getGlobalScope().client.close() } - Sentry.init { + initForTest { it.dsn = dsn } Sentry.setCurrentScopes(scopes) - Sentry.init { + initForTest { it.dsn = dsn } verify(scopes).close(eq(true)) @@ -148,7 +149,7 @@ class SentryTest { whenever(scopes.close()).then { Sentry.getGlobalScope().client.close() } whenever(scopes.close(anyOrNull())).then { Sentry.getGlobalScope().client.close() } - Sentry.init { + initForTest { it.dsn = dsn } Sentry.setCurrentScopes(scopes) @@ -160,7 +161,7 @@ class SentryTest { @Test fun `close calls scopes close with isRestarting false`() { val scopes = mock() - Sentry.init { + initForTest { it.dsn = dsn } Sentry.setCurrentScopes(scopes) @@ -171,7 +172,7 @@ class SentryTest { @Test fun `outboxPath should be created at initialization`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.cacheDirPath = getTempPath() sentryOptions = it @@ -185,7 +186,7 @@ class SentryTest { @Test fun `cacheDirPath should be created at initialization`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.cacheDirPath = getTempPath() sentryOptions = it @@ -199,7 +200,7 @@ class SentryTest { @Test fun `getCacheDirPathWithoutDsn should be created at initialization`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.cacheDirPath = getTempPath() sentryOptions = it @@ -214,7 +215,7 @@ class SentryTest { @Test fun `Init sets SystemOutLogger if logger is NoOp and debug is enabled`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.cacheDirPath = getTempPath() sentryOptions = it @@ -226,7 +227,7 @@ class SentryTest { @Test fun `scope changes are isolated to a thread`() { - Sentry.init { + initForTest { it.dsn = dsn } Sentry.configureScope { @@ -251,10 +252,10 @@ class SentryTest { @Test fun `warns about multiple Sentry initializations`() { val logger = mock() - Sentry.init { + initForTest { it.dsn = dsn } - Sentry.init { + initForTest { it.dsn = dsn it.setDebug(true) it.setLogger(logger) @@ -268,8 +269,8 @@ class SentryTest { @Test fun `warns about multiple Sentry initializations with string overload`() { val logger = mock() - Sentry.init(dsn) - Sentry.init { + initForTest(dsn) + initForTest { it.dsn = dsn it.setDebug(true) it.setLogger(logger) @@ -292,7 +293,7 @@ class SentryTest { try { // initialize Sentry with empty DSN and enable loading properties from external sources - Sentry.init { + initForTest { it.isEnableExternalConfiguration = true } assertTrue(ScopesAdapter.getInstance().isEnabled) @@ -303,7 +304,7 @@ class SentryTest { @Test fun `initializes Sentry with enabled=false, thus disabling Sentry even if dsn is set`() { - Sentry.init { + initForTest { it.isEnabled = false it.dsn = "http://key@localhost/proj" } @@ -320,7 +321,7 @@ class SentryTest { @Test fun `initializes Sentry with enabled=false, thus disabling Sentry even if dsn is null`() { - Sentry.init { + initForTest { it.isEnabled = false } @@ -337,7 +338,7 @@ class SentryTest { @Test fun `initializes Sentry with dsn = null, throwing IllegalArgumentException`() { val exception = - assertThrows(java.lang.IllegalArgumentException::class.java) { Sentry.init() } + assertThrows(java.lang.IllegalArgumentException::class.java) { initForTest() } assertEquals( "DSN is required. Use empty string or set enabled to false in SentryOptions to disable SDK.", exception.message @@ -346,7 +347,7 @@ class SentryTest { @Test fun `captureUserFeedback gets forwarded to client`() { - Sentry.init { it.dsn = dsn } + initForTest { it.dsn = dsn } val client = createSentryClientMock() Sentry.getCurrentScopes().bindClient(client) @@ -363,7 +364,7 @@ class SentryTest { @Test fun `startTransaction sets operation and description`() { - Sentry.init { + initForTest { it.dsn = dsn it.tracesSampleRate = 1.0 } @@ -376,7 +377,7 @@ class SentryTest { @Test fun `isCrashedLastRun returns true if crashedLastRun is set`() { - Sentry.init { + initForTest { it.dsn = dsn } @@ -389,7 +390,7 @@ class SentryTest { fun `profilingTracesDirPath should be created and cleared at initialization when profiling is enabled`() { val tempPath = getTempPath() var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.profilesSampleRate = 1.0 it.cacheDirPath = tempPath @@ -424,7 +425,7 @@ class SentryTest { assertTrue(oldProfile.exists()) assertTrue(newProfile.exists()) - Sentry.init { + initForTest { it.dsn = dsn it.profilesSampleRate = 1.0 it.cacheDirPath = tempPath @@ -440,7 +441,7 @@ class SentryTest { fun `profilingTracesDirPath should not be created and cleared when profiling is disabled`() { val tempPath = getTempPath() var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.profilesSampleRate = 0.0 it.cacheDirPath = tempPath @@ -459,7 +460,7 @@ class SentryTest { // init Sentry in another thread val thread = Thread() { - Sentry.init { + initForTest { it.dsn = dsn it.isDebug = true } @@ -486,7 +487,7 @@ class SentryTest { // init Sentry in another thread val thread = Thread() { - Sentry.init { + initForTest { it.dsn = dsn it.isDebug = true it.beforeSend = SentryOptions.BeforeSendCallback { event, hint -> @@ -537,7 +538,7 @@ class SentryTest { // init Sentry in another thread val thread = Thread() { - Sentry.init({ + initForTest({ it.dsn = dsn it.isDebug = true it.beforeSend = SentryOptions.BeforeSendCallback { event, hint -> @@ -581,7 +582,7 @@ class SentryTest { val logger = mock() val initException = Exception("init") - Sentry.init({ + initForTest({ it.dsn = dsn it.isDebug = true it.setLogger(logger) @@ -612,7 +613,7 @@ class SentryTest { fun `overrides envelope cache if it's not set`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.cacheDirPath = getTempPath() sentryOptions = it @@ -625,7 +626,7 @@ class SentryTest { fun `does not override envelope cache if it's already set`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.cacheDirPath = getTempPath() it.setEnvelopeDiskCache(CustomEnvelopCache()) @@ -639,7 +640,7 @@ class SentryTest { fun `overrides modules loader if it's not set`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn sentryOptions = it } @@ -651,7 +652,7 @@ class SentryTest { fun `does not override modules loader if it's already set`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.setModulesLoader(CustomModulesLoader()) sentryOptions = it @@ -664,7 +665,7 @@ class SentryTest { fun `overrides debug meta loader if it's not set`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn sentryOptions = it } @@ -676,7 +677,7 @@ class SentryTest { fun `does not override debug meta loader if it's already set`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.setDebugMetaLoader(CustomDebugMetaLoader()) sentryOptions = it @@ -689,7 +690,7 @@ class SentryTest { fun `overrides main thread checker if it's not set`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn sentryOptions = it } @@ -701,7 +702,7 @@ class SentryTest { fun `does not override main thread checker if it's already set`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.threadChecker = CustomThreadChecker() sentryOptions = it @@ -714,7 +715,7 @@ class SentryTest { fun `overrides collector if it's not set`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn sentryOptions = it } @@ -726,7 +727,7 @@ class SentryTest { fun `does not override collector if it's already set`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.addPerformanceCollector(CustomMemoryCollector()) sentryOptions = it @@ -739,7 +740,7 @@ class SentryTest { fun `init does not throw on executor shut down`() { val logger = mock() - Sentry.init { + initForTest { it.dsn = dsn it.profilesSampleRate = 1.0 it.cacheDirPath = getTempPath() @@ -753,7 +754,7 @@ class SentryTest { @Test fun `reportFullyDisplayed calls scopes reportFullyDisplayed`() { val scopes = mock() - Sentry.init { + initForTest { it.dsn = dsn } Sentry.setCurrentScopes(scopes) @@ -767,7 +768,7 @@ class SentryTest { val executorService = mock() whenever(executorService.isClosed).thenReturn(true) - Sentry.init { + initForTest { it.dsn = dsn it.executorService = executorService sentryOptions = it @@ -782,7 +783,7 @@ class SentryTest { val executorService = mock() whenever(executorService.isClosed).thenReturn(false) - Sentry.init { + initForTest { it.dsn = dsn it.executorService = executorService sentryOptions = it @@ -795,7 +796,7 @@ class SentryTest { fun `init notifies option observers`() { val optionsObserver = InMemoryOptionsObserver() - Sentry.init { + initForTest { it.dsn = dsn it.executorService = ImmediateExecutorService() @@ -828,7 +829,7 @@ class SentryTest { } val triggered = AtomicBoolean(false) - Sentry.init { + initForTest { it.dsn = dsn it.addOptionsObserver(optionsObserver) @@ -858,7 +859,7 @@ class SentryTest { fun `init finalizes previous session`() { lateinit var previousSessionFile: File - Sentry.init { + initForTest { it.dsn = dsn it.isDebug = true it.setLogger(SystemOutLogger()) @@ -895,7 +896,7 @@ class SentryTest { lateinit var previousSessionFile: File val triggered = AtomicBoolean(false) - Sentry.init { + initForTest { it.dsn = dsn it.release = "io.sentry.sample@2.0" @@ -931,7 +932,7 @@ class SentryTest { @Test fun `captureCheckIn gets forwarded to client`() { - Sentry.init { it.dsn = dsn } + initForTest { it.dsn = dsn } val client = createSentryClientMock() Sentry.getCurrentScopes().bindClient(client) @@ -951,7 +952,7 @@ class SentryTest { @Test fun `if send modules is false, uses NoOpModulesLoader`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.isSendModules = false sentryOptions = it @@ -962,7 +963,7 @@ class SentryTest { @Test fun `if Sentry is disabled through options with scope callback is executed`() { - Sentry.init { + initForTest { it.isEnabled = false } @@ -988,7 +989,7 @@ class SentryTest { val options = SentryOptions().also { it.dsn = dsn } whenever(scopes.options).thenReturn(options) - Sentry.init(options) + initForTest(options) Sentry.setCurrentScopes(scopes) Sentry.getSpan() @@ -1019,7 +1020,7 @@ class SentryTest { @Test fun `getSpan calls returns child span if globalHubMode is enabled, but the platform is not Android`() { PlatformTestManipulator.pretendIsAndroid(false) - Sentry.init({ + initForTest({ it.dsn = dsn it.tracesSampleRate = 1.0 it.sampleRate = 1.0 @@ -1034,7 +1035,7 @@ class SentryTest { @Test fun `getSpan calls returns child span if globalHubMode is disabled`() { - Sentry.init({ + initForTest({ it.dsn = dsn it.tracesSampleRate = 1.0 it.sampleRate = 1.0 @@ -1050,7 +1051,7 @@ class SentryTest { @Test fun `backpressure monitor is a NoOp if handling is disabled`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.isEnableBackpressureHandling = false sentryOptions = it @@ -1062,7 +1063,7 @@ class SentryTest { fun `backpressure monitor is set if handling is enabled`() { var sentryOptions: SentryOptions? = null - Sentry.init { + initForTest { it.dsn = dsn it.isEnableBackpressureHandling = true sentryOptions = it @@ -1074,7 +1075,7 @@ class SentryTest { fun `init calls samplers if isEnableAppStartProfiling is true`() { val mockSampleTracer = mock() val mockProfilesSampler = mock() - Sentry.init { + initForTest { it.dsn = dsn it.tracesSampleRate = 1.0 it.isEnableAppStartProfiling = true @@ -1105,7 +1106,7 @@ class SentryTest { fun `init calls app start profiling samplers in the background`() { val mockSampleTracer = mock() val mockProfilesSampler = mock() - Sentry.init { + initForTest { it.dsn = dsn it.tracesSampleRate = 1.0 it.isEnableAppStartProfiling = true @@ -1124,7 +1125,7 @@ class SentryTest { fun `init does not call app start profiling samplers if cache dir is null`() { val mockSampleTracer = mock() val mockProfilesSampler = mock() - Sentry.init { + initForTest { it.dsn = dsn it.tracesSampleRate = 1.0 it.isEnableAppStartProfiling = true @@ -1143,7 +1144,7 @@ class SentryTest { fun `init does not call app start profiling samplers if performance is disabled`() { val logger = mock() val mockProfilesSampler = mock() - Sentry.init { + initForTest { it.dsn = dsn it.tracesSampleRate = null it.isEnableAppStartProfiling = true @@ -1165,7 +1166,7 @@ class SentryTest { val appStartProfilingConfigFile = File(path, "app_start_profiling_config") appStartProfilingConfigFile.createNewFile() assertTrue(appStartProfilingConfigFile.exists()) - Sentry.init { + initForTest { it.dsn = dsn it.executorService = ImmediateExecutorService() it.cacheDirPath = path @@ -1180,7 +1181,7 @@ class SentryTest { val appStartProfilingConfigFile = File(path, "app_start_profiling_config") appStartProfilingConfigFile.createNewFile() assertTrue(appStartProfilingConfigFile.exists()) - Sentry.init { + initForTest { it.dsn = dsn it.cacheDirPath = path it.isEnableAppStartProfiling = true @@ -1195,7 +1196,7 @@ class SentryTest { fun `init saves SentryAppStartProfilingOptions to disk`() { var options = SentryOptions() val path = getTempPath() - Sentry.init { + initForTest { it.dsn = dsn it.cacheDirPath = path it.tracesSampleRate = 1.0 @@ -1219,7 +1220,7 @@ class SentryTest { fun `init on Android throws when not using SentryAndroidOptions`() { PlatformTestManipulator.pretendIsAndroid(true) assertFails("You are running Android. Please, use SentryAndroid.init.") { - Sentry.init { + initForTest { it.dsn = dsn } } @@ -1233,21 +1234,21 @@ class SentryTest { it.dsn = dsn it.mockName() } - Sentry.init(options) + initForTest(options) options.resetName() PlatformTestManipulator.pretendIsAndroid(false) } @Test fun `init on Java works when not using SentryAndroidOptions`() { - Sentry.init { + initForTest { it.dsn = dsn } } @Test fun `if globalHubMode on options is not set, uses false from init param`() { - Sentry.init({ o -> o.dsn = dsn }, false) + initForTest({ o -> o.dsn = dsn }, false) val s1 = Sentry.forkedRootScopes("s1") val s2 = Sentry.forkedRootScopes("s2") assertNotSame(s1, s2) @@ -1255,7 +1256,7 @@ class SentryTest { @Test fun `if globalHubMode on options is not set, uses true from init param`() { - Sentry.init({ o -> o.dsn = dsn }, true) + initForTest({ o -> o.dsn = dsn }, true) val s1 = Sentry.forkedRootScopes("s1") val s2 = Sentry.forkedRootScopes("s2") assertSame(s1, s2) @@ -1263,7 +1264,7 @@ class SentryTest { @Test fun `if globalHubMode on options is set, ignores false from init param`() { - Sentry.init({ o -> o.dsn = dsn; o.isGlobalHubMode = true }, false) + initForTest({ o -> o.dsn = dsn; o.isGlobalHubMode = true }, false) val s1 = Sentry.forkedRootScopes("s1") val s2 = Sentry.forkedRootScopes("s2") assertSame(s1, s2) @@ -1271,7 +1272,7 @@ class SentryTest { @Test fun `if globalHubMode on options is set, ignores true from init param`() { - Sentry.init({ o -> o.dsn = dsn; o.isGlobalHubMode = false }, true) + initForTest({ o -> o.dsn = dsn; o.isGlobalHubMode = false }, true) val s1 = Sentry.forkedRootScopes("s1") val s2 = Sentry.forkedRootScopes("s2") assertNotSame(s1, s2) diff --git a/sentry/src/test/java/io/sentry/SentryWrapperTest.kt b/sentry/src/test/java/io/sentry/SentryWrapperTest.kt index 6fd32ac57b1..36660ef026c 100644 --- a/sentry/src/test/java/io/sentry/SentryWrapperTest.kt +++ b/sentry/src/test/java/io/sentry/SentryWrapperTest.kt @@ -1,5 +1,6 @@ package io.sentry +import io.sentry.test.initForTest import java.util.concurrent.CompletableFuture import java.util.concurrent.ExecutorService import java.util.concurrent.Executors @@ -28,7 +29,7 @@ class SentryWrapperTest { @Test fun `scopes is reset to state within the thread after isolated supply is done`() { - Sentry.init { + initForTest { it.dsn = dsn it.beforeSend = SentryOptions.BeforeSendCallback { event, hint -> event @@ -66,7 +67,7 @@ class SentryWrapperTest { fun `wrapped supply async isolates Scopes`() { val capturedEvents = mutableListOf() - Sentry.init { + initForTest { it.dsn = dsn it.beforeSend = SentryOptions.BeforeSendCallback { event, hint -> capturedEvents.add(event) @@ -118,7 +119,7 @@ class SentryWrapperTest { fun `wrapped callable isolates Scopes`() { val capturedEvents = mutableListOf() - Sentry.init { + initForTest { it.dsn = dsn it.beforeSend = SentryOptions.BeforeSendCallback { event, hint -> capturedEvents.add(event) @@ -165,7 +166,7 @@ class SentryWrapperTest { @Test fun `scopes is reset to state within the thread after isolated callable is done`() { - Sentry.init { + initForTest { it.dsn = dsn } diff --git a/sentry/src/test/java/io/sentry/clientreport/ClientReportMultiThreadingTest.kt b/sentry/src/test/java/io/sentry/clientreport/ClientReportMultiThreadingTest.kt index 6cb22fc7efc..29809e56e6c 100644 --- a/sentry/src/test/java/io/sentry/clientreport/ClientReportMultiThreadingTest.kt +++ b/sentry/src/test/java/io/sentry/clientreport/ClientReportMultiThreadingTest.kt @@ -8,6 +8,7 @@ import io.sentry.SentryEnvelopeItem import io.sentry.SentryOptions import io.sentry.dsnString import io.sentry.protocol.SentryId +import io.sentry.test.initForTest import java.util.UUID import java.util.concurrent.ExecutorCompletionService import java.util.concurrent.Executors @@ -182,7 +183,7 @@ class ClientReportMultiThreadingTest { } private fun setupSentry(callback: Sentry.OptionsConfiguration? = null) { - Sentry.init { options -> + initForTest { options -> options.dsn = dsnString callback?.configure(options) opts = options diff --git a/sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt b/sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt index 138ea12d312..23f086dd04c 100644 --- a/sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt +++ b/sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt @@ -29,6 +29,7 @@ import io.sentry.hints.Retryable import io.sentry.protocol.SentryId import io.sentry.protocol.SentryTransaction import io.sentry.protocol.User +import io.sentry.test.initForTest import io.sentry.util.HintUtils import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @@ -192,7 +193,7 @@ class ClientReportTest { } private fun setupSentry(callback: Sentry.OptionsConfiguration? = null) { - Sentry.init { options -> + initForTest { options -> options.dsn = dsnString callback?.configure(options) opts = options