Skip to content

Commit dbad316

Browse files
test(android): Wait for the previous session move in InternalSentrySdkTest (#6358)
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: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Nelson Osacky <nelson.osacky@sentry.io>
1 parent 1569178 commit dbad316

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

‎sentry-android-core/src/test/java/io/sentry/android/core/InternalSentrySdkTest.kt‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ import java.io.ByteArrayOutputStream
3838
import java.io.InputStreamReader
3939
import java.util.concurrent.atomic.AtomicReference
4040
import kotlin.test.BeforeTest
41-
import kotlin.test.Ignore
4241
import kotlin.test.Test
4342
import kotlin.test.assertEquals
4443
import kotlin.test.assertNotEquals
4544
import kotlin.test.assertNotNull
4645
import kotlin.test.assertNull
4746
import kotlin.test.assertTrue
47+
import org.awaitility.kotlin.await
4848
import org.junit.runner.RunWith
4949
import org.mockito.kotlin.mock
5050
import org.mockito.kotlin.whenever
@@ -87,6 +87,12 @@ class InternalSentrySdkTest {
8787
}
8888
}
8989

90+
// Sentry.init moves any leftover session.json to previous_session.json on the executor. Wait
91+
// for that to finish, otherwise it can move the session a test has just persisted. Test
92+
// options set sessionFlushTimeoutMillis to 0, so waitPreviousSessionFlush() only polls.
93+
val cache = options.envelopeDiskCache as EnvelopeCache
94+
await.until { cache.waitPreviousSessionFlush() }
95+
9096
capturedEnvelopes.clear()
9197
}
9298

@@ -634,14 +640,6 @@ class InternalSentrySdkTest {
634640
assertThat(activeSession.get().sessionId).isNotEqualTo(oldSid)
635641
}
636642

637-
// Flaky: intermittently fails with FileNotFoundException reading session.json at the
638-
// `sessionFile.reader()` call below, i.e. persistCurrentSession() did not leave a session file
639-
// on disk by the time this test reads it back. Seen across unrelated PRs, e.g.:
640-
// 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
641-
// 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
642-
// Disabling until root-caused; see https://github.com/getsentry/sentry-java/pull/5990 for the
643-
// code under test.
644-
@Ignore("Flaky: intermittently fails to find the persisted session.json, needs root-causing")
645643
@Test
646644
fun `updateSessionForDroppedEventNonTerminating flags an unhandled error without sending an envelope`() {
647645
val fixture = Fixture()

0 commit comments

Comments
 (0)