-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash on double SDK init (#2679)
* all calls to ISentryExecutorService are now wrapped in a try catch block * closing the hub will close the profiler and the performance collector * added ui test for double init * added ISentryExecutorService.close and isClosed internal methods * profiling is now stopped on executorService exceptions * ISentryExecutorService is re-init in Sentry.init if it was shutdown
- Loading branch information
1 parent
544da32
commit 64bd675
Showing
28 changed files
with
460 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/SdkInitTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package io.sentry.uitest.android | ||
|
||
import androidx.lifecycle.Lifecycle | ||
import androidx.test.core.app.launchActivity | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import io.sentry.ProfilingTraceData | ||
import io.sentry.Sentry | ||
import io.sentry.android.core.SentryAndroidOptions | ||
import io.sentry.assertEnvelopeItem | ||
import io.sentry.protocol.SentryTransaction | ||
import org.junit.runner.RunWith | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class SdkInitTests : BaseUiTest() { | ||
|
||
@Test | ||
fun doubleInitDoesNotThrow() { | ||
initSentry(false) { options: SentryAndroidOptions -> | ||
options.tracesSampleRate = 1.0 | ||
options.profilesSampleRate = 1.0 | ||
} | ||
val transaction = Sentry.startTransaction("e2etests", "testInit") | ||
val sampleScenario = launchActivity<EmptyActivity>() | ||
initSentry(false) { options: SentryAndroidOptions -> | ||
options.tracesSampleRate = 1.0 | ||
options.profilesSampleRate = 1.0 | ||
} | ||
transaction.finish() | ||
sampleScenario.moveToState(Lifecycle.State.DESTROYED) | ||
val transaction2 = Sentry.startTransaction("e2etests", "testInit") | ||
transaction2.finish() | ||
} | ||
|
||
@Test | ||
fun doubleInitWithSameOptionsDoesNotThrow() { | ||
val options = SentryAndroidOptions() | ||
|
||
initSentry(true) { | ||
it.tracesSampleRate = 1.0 | ||
it.profilesSampleRate = 1.0 | ||
// We use the same executorService before and after closing the SDK | ||
it.executorService = options.executorService | ||
it.isDebug = true | ||
} | ||
val transaction = Sentry.startTransaction("e2etests", "testInit") | ||
val sampleScenario = launchActivity<EmptyActivity>() | ||
initSentry(true) { | ||
it.tracesSampleRate = 1.0 | ||
it.profilesSampleRate = 1.0 | ||
// We use the same executorService before and after closing the SDK | ||
it.executorService = options.executorService | ||
it.isDebug = true | ||
} | ||
relayIdlingResource.increment() | ||
transaction.finish() | ||
sampleScenario.moveToState(Lifecycle.State.DESTROYED) | ||
val transaction2 = Sentry.startTransaction("e2etests2", "testInit") | ||
transaction2.finish() | ||
|
||
relay.assert { | ||
findEnvelope { | ||
assertEnvelopeItem<SentryTransaction>(it.items.toList()).transaction == "e2etests2" | ||
}.assert { | ||
val transactionItem: SentryTransaction = it.assertItem() | ||
// Profiling uses executorService, so if the executorService is shutdown it would fail | ||
val profilingTraceData: ProfilingTraceData = it.assertItem() | ||
it.assertNoOtherItems() | ||
assertEquals("e2etests2", transactionItem.transaction) | ||
assertEquals("e2etests2", profilingTraceData.transactionName) | ||
} | ||
assertNoOtherEnvelopes() | ||
assertNoOtherRequests() | ||
} | ||
} | ||
} |
Oops, something went wrong.