Skip to content

fix: [SDK-5816] fix flaky unit tests and a login token race - #1816

Open
fadi-george wants to merge 8 commits into
mainfrom
fadi/sdk-5816
Open

fadi-george wants to merge 8 commits into
mainfrom
fadi/sdk-5816

Conversation

@fadi-george

@fadi-george fadi-george commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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.setBadgeCountAndWait waited for the system setBadgeCount completion, 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.testLoggingInWithATokenAnswersAPendingAskForThatUser asserted the token ask had already happened after a fixed 0.5s wait. It now polls pendingTokenAsks(), which reads the ask without consuming it (unlike askForToken).
  • While investigating IamFetchIdentityVerificationTests.testARejectedFetchParksWithoutReportingTheTokenItUsed, found a real SDK race: login published 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. setNewInternalUser now sets the token on the identity model before publishing it. The existing storeJwtOrRearmAsk still 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.
  • SubscriptionUpdateRaceTests waited 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 (dispatchQueue and updateRequestQueue are now internal, no behavior change).
  • UserStateReportingTests.testAnIdentifyUserThatCompletesAfterAUserSwitchDoesNotReportThatUser and the IAM fetch test above never failed locally, so their failure messages now report the models, tokens, and requests involved.
  • The JWT pending-ask test still failed 2 of 14 CI runs. Its new failure message showed a Create User for user A signed with token-b, a token only an earlier test uses: that test's executors persisted user A's state after teardown cleared UserDefaults, and the next start uncached 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.
  • The badge test no longer verifies the system call completes, which it wasn't meant to test.

Testing

Unit testing

  • Badge and JWT suites: 20 iterations with -run-tests-until-failure on an iOS 26.5 simulator, 520 test runs, 0 failures.
  • Login race: testANewUserIsPublishedWithTheTokenItLoggedInWith checks 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.
  • CI: 10 consecutive passing runs of Build and Test on 4f8a1e9.
  • User and IAM test bundles: 3 iterations, all pass except 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

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • User login / Identity Verification
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fadi-george
fadi-george requested a review from nan-li November 20, 2026 00:00
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>
@fadi-george fadi-george changed the title test: [SDK-5816] fix flaky badge and JWT pending-ask unit tests fix: [SDK-5816] fix flaky unit tests and a login token race Nov 20, 2026
fadi-george and others added 6 commits November 19, 2026 17:13
… 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>
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