Skip to content

test(android): Wait for the previous session move in InternalSentrySdkTest - #6358

Merged
runningcode merged 1 commit into
mainfrom
test/internal-sdk-session-flush-race
Oct 23, 2026
Merged

runningcode merged 1 commit into
mainfrom
test/internal-sdk-session-flush-race

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

📜 Description

InternalSentrySdkTest.Fixture.init now waits for Sentry.init's MovePreviousSession task before the test acts. This change also re-enables updateSessionForDroppedEventNonTerminating 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 envelope was the flakiest test in CI between Oct 15 and Oct 22. It failed 35 times across 29 branches, once on main, which is about 1 in 12 Build runs. The CI error was FileNotFoundException ... session.json.

Cause:

  • Sentry.init puts MovePreviousSession on the real executor. That task renames any session.json to previous_session.json.
  • The test writes the live session to session.json on the calling thread, through persistCurrentSession.
  • If the executor runs the move between that write and the test reading the file back, the file is gone.
  • PreviousSessionFinalizer then sends the moved session as an extra envelope. That causes the related flakes captureEnvelopeNonTerminating then a crash… (expected 2 envelopes, got 3) and updateSessionForDroppedEventNonTerminating then endSession… (expected 1, got 2).

Test options set sessionFlushTimeoutMillis = 0, so waitPreviousSessionFlush() 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:

  • To force the bad ordering, I temporarily changed MovePreviousSession.run() (not committed) to wait until session.json exists before moving it. With that change, the test on main fails with the same FileNotFoundException as CI. With this PR, all 26 tests pass, including the re-enabled one.
  • Without the change, all 26 tests pass.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

Decide whether the startup race between MovePreviousSession and persistCurrentSession needs an SDK fix.

#skip-changelog

via no.

--

View Junior Session [Sentry]

…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>
@sentry

sentry Bot commented Oct 22, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.61.1 (1) release

⚙️ sentry-android Build Distribution Settings

@runningcode
runningcode marked this pull request as ready for review October 23, 2026 07:40
@runningcode
runningcode merged commit dbad316 into main Oct 23, 2026
34 checks passed
@runningcode
runningcode deleted the test/internal-sdk-session-flush-race branch October 23, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant