From 0bc4ce8caa06535279a8b5eac42cb4ac7261334d Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:05:14 +0000 Subject: [PATCH] test(android): Wait for the previous session move in InternalSentrySdkTest Sentry.init moves session.json to previous_session.json on the executor. When that task ran after a test persisted the live session, the test could no longer read session.json, and PreviousSessionFinalizer sent the moved session as an extra envelope. Wait for the move in the fixture and re-enable the test that was ignored for the same flake. Co-Authored-By: Nelson Osacky --- .../sentry/android/core/InternalSentrySdkTest.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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 ba0322c7a1e..031df4c523c 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 @@ -38,13 +38,13 @@ import java.io.ByteArrayOutputStream import java.io.InputStreamReader import java.util.concurrent.atomic.AtomicReference import kotlin.test.BeforeTest -import kotlin.test.Ignore import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotEquals import kotlin.test.assertNotNull import kotlin.test.assertNull import kotlin.test.assertTrue +import org.awaitility.kotlin.await import org.junit.runner.RunWith import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @@ -87,6 +87,12 @@ class InternalSentrySdkTest { } } + // Sentry.init moves any leftover session.json to previous_session.json on the executor. Wait + // for that to finish, otherwise it can move the session a test has just persisted. Test + // options set sessionFlushTimeoutMillis to 0, so waitPreviousSessionFlush() only polls. + val cache = options.envelopeDiskCache as EnvelopeCache + await.until { cache.waitPreviousSessionFlush() } + capturedEnvelopes.clear() } @@ -634,14 +640,6 @@ class InternalSentrySdkTest { assertThat(activeSession.get().sessionId).isNotEqualTo(oldSid) } - // Flaky: intermittently fails with FileNotFoundException reading session.json at the - // `sessionFile.reader()` call below, i.e. persistCurrentSession() did not leave a session file - // on disk by the time this test reads it back. Seen across unrelated PRs, e.g.: - // https://scans.gradle.com/s/55fnn6xhtfyfq/tests/task/:sentry-android-core:testReleaseUnitTest/details/io.sentry.android.core.InternalSentrySdkTest/updateSessionForDroppedEventNonTerminating%20flags%20an%20unhandled%20error%20without%20sending%20an%20envelope?top-execution=1 - // https://scans.gradle.com/s/ojzzz4yxag7rw/tests/task/:sentry-android-core:testReleaseUnitTest/details/io.sentry.android.core.InternalSentrySdkTest/updateSessionForDroppedEventNonTerminating%20flags%20an%20unhandled%20error%20without%20sending%20an%20envelope?top-execution=1 - // Disabling until root-caused; see https://github.com/getsentry/sentry-java/pull/5990 for the - // code under test. - @Ignore("Flaky: intermittently fails to find the persisted session.json, needs root-causing") @Test fun `updateSessionForDroppedEventNonTerminating flags an unhandled error without sending an envelope`() { val fixture = Fixture()