Repository navigation
fix: [SDK-5816] fix flaky unit tests and a login token race - #1816
Merged
Merged
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>
abdulraqeeb33
approved these changes
Nov 20, 2026
abdulraqeeb33
left a comment
Contributor
There was a problem hiding this comment.
Reviewed 4f8a1e99. The login race fix is right: the token lands on the identity model before publish, so a concurrent IAM fetch cannot see a user without a token and re-ask.
Flake fixes look solid. Two nits on the new regression test and the badge helper.
…he unawaited badge completion Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…il a wait Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
abdulraqeeb33
approved these changes
Nov 20, 2026
abdulraqeeb33
left a comment
Contributor
There was a problem hiding this comment.
Both nits fixed in ddbc74a.
- Race test goes through
loginand records the token at store-add, so it fails if the assignment moves after publish. - Badge helper no longer asserts in the unawaited system completion.
… fails Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A poll landing between the unpause and the session_count enqueue sent the queue without it, splitting the session's update into two requests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Work an earlier test leaves running can ask for the same user's token before this test logs in, and that ask reached the new listener. 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 two SDK races 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. That IAM test's real cause turned out to be the cross-test leak described below.OneSignalUserTests.testBasicCombiningUserUpdateDeltas_resultsInOneRequest:startNewSession()unpaused the operation repo before it enqueued itssession_countDelta, so a poll in between sent the queue without it and split the session's update into two Requests.startNewSession()now queues the session's Deltas first, then retries pending user requests, unpauses, and flushes. The retry stays right before the unpause, as before, so a Create User that fails again still pauses the repo. In production the old order only cost an extra Request.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.IamFetchIdentityVerificationTests.testARejectedFetchParksWithoutReportingTheTokenItUsed: its diagnostic showed the JWT listener hearing an ask for user A before this test had sent anything, raised by work an earlier test left running (the same leak). It andtestARejectedFetchRefetchesWhenAReplacementTokenAlreadyLandednow count only the asks the fetch step itself reports. Both still fail if a rejected fetch reports its token (checked with a temporary mutation).OneSignalCoreMocks.waitUntildefaults to 15s instead of 5s. A met condition returns at once, so this only matters when a CI runner stalls, which failed an unrelated custom events wait.EarlyTriggerTrackingTestsfailed once with the first IAM fetch never completing, outside any runner stall. Its waits now report where the fetch stopped (IDs, deferral, RYW tokens, requests).Testing
Unit testing
-run-tests-until-failureon an iOS 26.5 simulator, 520 test runs, 0 failures.testLoginPublishesTheNewUserWithTheTokenItLoggedInWithlogs in and records the identity model's token at the moment the store adds it, so it fails if the token is set after the user is published. 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