-
-
Notifications
You must be signed in to change notification settings - Fork 465
Fix flaky SdkInitTests #4661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix flaky SdkInitTests #4661
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ 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.IConnectionStatusProvider | ||
| import io.sentry.ProfilingTraceData | ||
| import io.sentry.Sentry | ||
| import io.sentry.SentryIntegrationPackageStorage | ||
|
|
@@ -23,19 +24,51 @@ import shark.AndroidReferenceMatchers | |
| import shark.IgnoredReferenceMatcher | ||
| import shark.ReferencePattern | ||
|
|
||
| /** Test connection status provider that always reports connected. */ | ||
| private class AlwaysOnlineStatusProvider : IConnectionStatusProvider { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, wondering if it's still going to fail because the device does not have internet connection, but we're saying here that it does? Shall we also try to enable it via e.g. executing
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think it's a problem, because it's sending to localhost anyway, except for a single test ( |
||
|
|
||
| override fun close() { | ||
| // No-op for test implementation | ||
| } | ||
|
|
||
| override fun getConnectionStatus(): IConnectionStatusProvider.ConnectionStatus { | ||
| return IConnectionStatusProvider.ConnectionStatus.CONNECTED | ||
| } | ||
|
|
||
| override fun getConnectionType(): String? { | ||
| return null | ||
| } | ||
|
|
||
| override fun addConnectionStatusObserver( | ||
| observer: IConnectionStatusProvider.IConnectionStatusObserver | ||
| ): Boolean { | ||
| return false | ||
| } | ||
|
|
||
| override fun removeConnectionStatusObserver( | ||
| observer: IConnectionStatusProvider.IConnectionStatusObserver | ||
| ) { | ||
| // no-op | ||
| } | ||
| } | ||
|
|
||
| @RunWith(AndroidJUnit4::class) | ||
| class SdkInitTests : BaseUiTest() { | ||
| @Test | ||
| fun doubleInitDoesNotThrow() { | ||
| initSentry(false) { options: SentryAndroidOptions -> | ||
| options.tracesSampleRate = 1.0 | ||
| options.profilesSampleRate = 1.0 | ||
| options.readTimeoutMillis = 500 | ||
| options.connectionTimeoutMillis = 500 | ||
| } | ||
| val transaction = Sentry.startTransaction("e2etests", "testInit") | ||
| val sampleScenario = launchActivity<EmptyActivity>() | ||
| initSentry(false) { options: SentryAndroidOptions -> | ||
| options.tracesSampleRate = 1.0 | ||
| options.profilesSampleRate = 1.0 | ||
| options.readTimeoutMillis = 500 | ||
| options.connectionTimeoutMillis = 500 | ||
| } | ||
| transaction.finish() | ||
| sampleScenario.moveToState(Lifecycle.State.DESTROYED) | ||
|
|
@@ -53,6 +86,9 @@ class SdkInitTests : BaseUiTest() { | |
| // We use the same executorService before and after closing the SDK | ||
| it.executorService = options.executorService | ||
| it.isDebug = true | ||
| it.readTimeoutMillis = 500 | ||
| it.connectionTimeoutMillis = 500 | ||
| it.connectionStatusProvider = AlwaysOnlineStatusProvider() | ||
| } | ||
| val transaction = Sentry.startTransaction("e2etests", "testInit") | ||
| val sampleScenario = launchActivity<EmptyActivity>() | ||
|
|
@@ -62,6 +98,9 @@ class SdkInitTests : BaseUiTest() { | |
| // We use the same executorService before and after closing the SDK | ||
| it.executorService = options.executorService | ||
| it.isDebug = true | ||
| it.readTimeoutMillis = 500 | ||
| it.connectionTimeoutMillis = 500 | ||
| it.connectionStatusProvider = AlwaysOnlineStatusProvider() | ||
| } | ||
| relayIdlingResource.increment() | ||
| relayIdlingResource.increment() | ||
|
|
@@ -103,7 +142,12 @@ class SdkInitTests : BaseUiTest() { | |
| // Let's make the first request timeout | ||
| relay.addTimeoutResponse() | ||
|
|
||
| initSentry(true) { options: SentryAndroidOptions -> options.tracesSampleRate = 1.0 } | ||
| initSentry(true) { options: SentryAndroidOptions -> | ||
| options.tracesSampleRate = 1.0 | ||
| options.readTimeoutMillis = 500 | ||
| options.connectionTimeoutMillis = 500 | ||
| options.connectionStatusProvider = AlwaysOnlineStatusProvider() | ||
| } | ||
|
|
||
| Sentry.startTransaction("beforeRestart", "emptyTransaction").finish() | ||
|
|
||
|
|
@@ -120,6 +164,9 @@ class SdkInitTests : BaseUiTest() { | |
| initSentry(true) { options: SentryAndroidOptions -> | ||
| options.tracesSampleRate = 1.0 | ||
| options.profilesSampleRate = 1.0 | ||
| options.readTimeoutMillis = 500 | ||
| options.connectionTimeoutMillis = 500 | ||
| options.connectionStatusProvider = AlwaysOnlineStatusProvider() | ||
| } | ||
| val afterRestart = System.currentTimeMillis() | ||
| val restartMs = afterRestart - beforeRestart | ||
|
|
@@ -156,6 +203,7 @@ class SdkInitTests : BaseUiTest() { | |
| initSentry(true) { options: SentryAndroidOptions -> | ||
| options.tracesSampleRate = 1.0 | ||
| options.flushTimeoutMillis = 3000 | ||
| options.connectionStatusProvider = AlwaysOnlineStatusProvider() | ||
| } | ||
|
|
||
| Sentry.startTransaction("beforeRestart", "emptyTransaction").finish() | ||
|
|
@@ -170,6 +218,7 @@ class SdkInitTests : BaseUiTest() { | |
| initSentry(true) { options: SentryAndroidOptions -> | ||
| options.tracesSampleRate = 1.0 | ||
| options.profilesSampleRate = 1.0 | ||
| options.connectionStatusProvider = AlwaysOnlineStatusProvider() | ||
| } | ||
| val afterRestart = System.currentTimeMillis() | ||
| val restartMs = afterRestart - beforeRestart | ||
|
|
@@ -224,6 +273,9 @@ class SdkInitTests : BaseUiTest() { | |
| initSentry(false) { options: SentryAndroidOptions -> | ||
| options.tracesSampleRate = 1.0 | ||
| options.profilesSampleRate = 1.0 | ||
| options.readTimeoutMillis = 500 | ||
| options.connectionTimeoutMillis = 500 | ||
| options.connectionStatusProvider = AlwaysOnlineStatusProvider() | ||
| } | ||
| } | ||
| activityScenario.moveToState(Lifecycle.State.DESTROYED) | ||
|
|
@@ -244,6 +296,9 @@ class SdkInitTests : BaseUiTest() { | |
| initSentry(false) { options: SentryAndroidOptions -> | ||
| options.tracesSampleRate = 1.0 | ||
| options.profilesSampleRate = 1.0 | ||
| options.readTimeoutMillis = 500 | ||
| options.connectionTimeoutMillis = 500 | ||
| options.connectionStatusProvider = AlwaysOnlineStatusProvider() | ||
| } | ||
| initLatch.countDown() | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Receiver Cleanup Fails on RejectedExecutionException
When
unregisterReceiver()catches aRejectedExecutionException, the essential cleanup logic (unregistering the receiver, nullifying its reference, and updatingisStopped) is skipped. This leaves the receiver registered with the Android system and the integration in an inconsistent state, potentially causing resource leaks.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is legit - could you extract the logic into
unregisterReceiverInternalor something and then call it in thecatchblock? In that case I think it's fine to still do it on the calling thread