Repository navigation
fix: [SDK-5816] fix flaky unit tests and a login token race - #1816
Open
fadi-george wants to merge 8 commits into
Open
fadi-george wants to merge 8 commits into
fadi-george wants to merge 8 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A reader on another queue, like the in-app message fetch, could catch the new user before its token was stored and ask the app for one it had just supplied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… limit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The stress test could not catch the race without an injected delay, and the state its 200 logins left behind is the likely cause of a later test in the class timing out in CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…failures startNewSession unpauses the operation repo before it enqueues its Delta, so a poll in between split the batch. The identify and IAM fetch tests now report the models and requests involved, since they only fail in CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ests The persisted queue is shared with every executor, including ones earlier tests left running, so one could overwrite it while these tests waited. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…est left behind Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
One Line Summary
Fix flaky unit tests so CI passes reliably, and a login race found along the way.
Details
Motivation
These tests fail intermittently in CI on unrelated PRs (#1815 failed on the first two in separate attempts, and this PR's own CI hit the third).
Scope
OneSignalNotificationsTests.setBadgeCountAndWaitwaited for the systemsetBadgeCountcompletion, which can exceed 5s on a freshly booted simulator. The swizzled setter caches the count synchronously before calling the system, so the helper now waits on the cached count.UserJwtLifecycleTests.testLoggingInWithATokenAnswersAPendingAskForThatUserasserted the token ask had already happened after a fixed 0.5s wait. It now pollspendingTokenAsks(), which reads the ask without consuming it (unlikeaskForToken).IamFetchIdentityVerificationTests.testARejectedFetchParksWithoutReportingTheTokenItUsed, found a real SDK race:loginpublished the new user and stored its token a moment later, so a reader on another queue (the IAM fetch runs on a global queue) could find the user without a token and ask the app for one it had just supplied.setNewInternalUsernow sets the token on the identity model before publishing it. The existingstoreJwtOrRearmAskstill runs to clear the ask and release held work. This did not stop that IAM test flaking in CI, so its cause is still open.OneSignalUserTests.testBasicCombiningUserUpdateDeltas_resultsInOneRequest:startNewSession()unpauses the operation repo before it enqueues its Delta, so a poll in between split the batch into two Requests. The test suspends the repo's queue around that call and re-pauses before resuming.SubscriptionUpdateRaceTestswaited on the persisted update queue, which every subscription executor writes, including ones earlier tests left running. The tests now read their own executor's in-memory queue (dispatchQueueandupdateRequestQueueare now internal, no behavior change).UserStateReportingTests.testAnIdentifyUserThatCompletesAfterAUserSwitchDoesNotReportThatUserand the IAM fetch test above never failed locally, so their failure messages now report the models, tokens, and requests involved.token-b, a token only an earlier test uses: that test's executors persisted user A's state after teardown cleared UserDefaults, and the nextstartuncached it, so the new Create User signed with the stale token and never asked. The test now logs in as a user no other test uses. The cross-test leak itself is test-infra only and not fixed here.Testing
Unit testing
-run-tests-until-failureon an iOS 26.5 simulator, 520 test runs, 0 failures.testANewUserIsPublishedWithTheTokenItLoggedInWithchecks the published user already carries its token. The gap is too narrow to hit in a test on its own, so I confirmed the race by widening it with a temporary 1ms sleep under a 200-login stress loop: without the fix a reader asked the app for a token, with the fix it did not.UserConcurrencyTests.testIdentityExecutorConcurrency, which fails when repeated back to back with or without this change (19 of 20 without it).Manual testing
Not applicable, covered by unit tests.
Affected code checklist
Checklist
Overview
Testing
Final pass
🤖 Generated with Claude Code