fix(test): Fix flaky previous session finalization test#5139
Merged
Conversation
Use awaitility to wait for the previous session file to be deleted instead of asserting immediately. The PreviousSessionFinalizer runs as a separate task after the test's task in the single-threaded executor, so there is a race between the assertion and the file deletion. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. This PR will not appear in the changelog. 🤖 This preview updates automatically when you update the PR. |
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 91bb874 | 310.68 ms | 359.24 ms | 48.56 ms |
| e59e22a | 368.02 ms | 432.00 ms | 63.98 ms |
| fc5ccaf | 279.11 ms | 353.34 ms | 74.23 ms |
| d15471f | 315.20 ms | 370.22 ms | 55.02 ms |
| d15471f | 286.65 ms | 314.68 ms | 28.03 ms |
| d15471f | 342.08 ms | 415.44 ms | 73.35 ms |
| ad8da22 | 314.38 ms | 352.29 ms | 37.91 ms |
| cf708bd | 434.73 ms | 502.96 ms | 68.22 ms |
| abfcc92 | 309.54 ms | 380.32 ms | 70.78 ms |
| 91bb874 | 314.47 ms | 440.00 ms | 125.53 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 91bb874 | 1.58 MiB | 2.13 MiB | 559.07 KiB |
| e59e22a | 1.58 MiB | 2.20 MiB | 635.34 KiB |
| fc5ccaf | 1.58 MiB | 2.13 MiB | 557.54 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| ad8da22 | 1.58 MiB | 2.29 MiB | 719.83 KiB |
| cf708bd | 1.58 MiB | 2.11 MiB | 539.71 KiB |
| abfcc92 | 1.58 MiB | 2.13 MiB | 557.31 KiB |
| 91bb874 | 1.58 MiB | 2.13 MiB | 559.07 KiB |
alexander-alderman-webb
approved these changes
Mar 3, 2026
romtsn
approved these changes
Mar 3, 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.
Fix flaky test
if there is work enqueued, init finalizes previous session after that work is doneinSentryTest.The test submits work to the single-threaded executor that reads the previous session file and sets a
triggeredflag.Sentry.initthen enqueues thePreviousSessionFinalizer(which deletes the file) as a separate task after the test's task. The test was waiting fortriggeredto become true and then immediately asserting the file was deleted — but since the finalizer is a separate queued task, there's a race where the assertion runs before the finalizer has executed.Replace the immediate
assertFalse(previousSessionFile.exists())withawait.until { !previousSessionFile.exists() }to poll until the finalizer completes.#skip-changelog