Repository navigation
test(android): Wait for the previous session move in InternalSentrySdkTest - #6358
Merged
Merged
Conversation
…kTest 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 <nelson.osacky@sentry.io>
📲 Install BuildsAndroid
|
runningcode
marked this pull request as ready for review
October 23, 2026 07:40
runningcode
requested review from
0xadam-brown,
adinauer,
markushi,
romtsn and
runningcode
as code owners
October 23, 2026 07:40
runningcode
approved these changes
Oct 23, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
InternalSentrySdkTest.Fixture.initnow waits forSentry.init'sMovePreviousSessiontask before the test acts. This change also re-enablesupdateSessionForDroppedEventNonTerminating flags an unhandled error without sending an envelope, which had been@Ignored for the same flake.💡 Motivation and Context
updateSessionForDroppedEventNonTerminating increments errors for a handled error without sending an envelopewas the flakiest test in CI between Oct 15 and Oct 22. It failed 35 times across 29 branches, once onmain, which is about 1 in 12 Build runs. The CI error wasFileNotFoundException ... session.json.Cause:
Sentry.initputsMovePreviousSessionon the real executor. That task renames anysession.jsontoprevious_session.json.session.jsonon the calling thread, throughpersistCurrentSession.PreviousSessionFinalizerthen sends the moved session as an extra envelope. That causes the related flakescaptureEnvelopeNonTerminating then a crash…(expected 2 envelopes, got 3) andupdateSessionForDroppedEventNonTerminating then endSession…(expected 1, got 2).Test options set
sessionFlushTimeoutMillis = 0, sowaitPreviousSessionFlush()only checks the latch once without waiting. That's why the fixture polls it with Awaitility.The SDK may have the same race in production. A hybrid SDK that calls the non-terminating API right after init could have its live session moved and finalized. This PR only fixes the test.
💚 How did you test it?
Locally (JDK 21),
:sentry-android-core:testReleaseUnitTest --tests InternalSentrySdkTest:MovePreviousSession.run()(not committed) to wait untilsession.jsonexists before moving it. With that change, the test onmainfails with the sameFileNotFoundExceptionas CI. With this PR, all 26 tests pass, including the re-enabled one.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Decide whether the startup race between
MovePreviousSessionandpersistCurrentSessionneeds an SDK fix.#skip-changelog
via no.
--
View Junior Session [Sentry]