Repository navigation
test: fix flaky unit and ui tests - #1327
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] This PR appears safe to merge; no actionable issues were found. SummaryThis PR replaces timing-sensitive test waits with gates, waits for USDT controls before tapping, and removes template UI tests.
Acknowledgments: Reviews (1) · Last reviewed commit: "test: fix flaky unit and ui tests" · Reviewed by Greptile |
talosmachina
left a comment
There was a problem hiding this comment.
No findings. Replaces the clock-bound waits behind the flaky unit and UI tests with event gates, drops backup requests that reach the queue after a wipe or restore began, bounds the test step in CI and removes the Xcode template UI tests. Reviewed 11a40ce, full tier, static: iOS does not build on Linux, so nothing was run here.
What I checked, and 6 candidates I ruled out
Read in full: the whole diff, plus BackupService.swift around markBackupRequired, scheduleBackup, runScheduledBackup, retryPendingBackups, requestStopObservingBackups, scheduleFullBackup and the status observers; Deadline.swift, AppReset.runRemoteCleanup, TabBar.shouldShow, AsyncGate, makeIsolatedDefaults
Call sites traced: setWiping / setRestoring (AppReset, AppScene restore, RestoreWalletView, prepareForRestore), scheduleFullBackup (AppScene after wallet start), withDeadline
CI: Run Integration Tests, build-local, SwiftFormat and validate green; Run Tests still pending when I reviewed
Ruled out
- The new skip branch in
scheduleBackupclearsrunningunder a live upload: it clears only whenbackupJobsandrunningBackupTasksare both empty for the category, read on the same.backupqueue that registers them, so an in-flighttriggerBackupor retry keeps its flag and clears it itself at the end ofrunBackup. - Clearing
runningre-triggers the observer during the wipe: the per-category publisher dedupes onsyncedandrequiredonly, and the sink checksshouldSkipBackupfirst. After a restore,scheduleFullBackupseesisRequired && !runningand schedules, which is the stuck case the PR describes. - Moving
shouldSkipBackupahead of the foreground-generation guard changes the foreground path: on that pathrunBackuphas already resetrunningand removed its task beforescheduleBackupruns, so the earlier return only adds a redundantrunning: false. withDeadline(until:)with a gate that never opens: in the identity-check test the operation cannot finish before the read is entered, and the gate always opens there, so the deadline ends the wait exactly when the cleanup is held, with no clock.ConnectionGate.reached(by:)loses the wake-up: both the helper and its watcher task are on the main actor, soreachedWaiteris set insidewithCheckedContinuationbefore the watcher can run.ProfileOperationGatebufferstruein an unbounded stream, so a gate reached before the assert still reads true.- The 55-minute step limit does not fit in the 60-minute job: on the three failed master runs and on the slowest recent failure (run 42610538883, a 54m11s test step), setup before the test step took 1 to 2 minutes and the upload 16 to 30 s, so 55 minutes leaves room. Longest test in the last green run: 103 s (the USDT receive UI test), well under the 300 s allowance. The removed template tests were not referenced from any scheme or skip list; the UI test target is a synchronized folder.
Merge confidence: 4/5. Run Tests had not finished when I reviewed, and the scheduleBackup fix is covered only by a race that failed about 1 in 200 runs, not by a test that pins it.
Reviewer model: claude-opus-5-5
Reasoning effort: Unknown (the reviewing session's metadata does not record it)
pwltr
left a comment
There was a problem hiding this comment.
Reviewed 11a40ce. No issues found.
The flaky tests now wait for the state they need instead of a short deadline, and fail at once if the operation ends without reaching it. scheduleBackup drops a request that arrives during a wipe or restore on every path and clears its running flag only when nothing else holds the category.
Review details
General review
Model: Claude Opus 5.5
Reasoning effort: high
|
Merging: approved on 11a40ce, CI green, no open threads. |
This PR makes the
Run Testscheck reliable. It fixes the causes of the flaky failures seen on master and on PRs, rather than retrying the job or lengthening timeouts, and it makes a stuck run fail fast instead of hitting the job's one-hour limit.The check failed on three master runs (caf4f7d21, 2826a88e1 and 21e87d67a). It also failed three times on #1323. Across the last 100 failed runs on all branches, the USDT UI test was the most frequent flake.
Description
UsdtWalletUITests:testReceiveAndInvalidPaymentStaySeparateFromBitcoinhad two failure modes.PaykitSdkIdentityCheckTests: the abandoned-cleanup test gave the wipe a 100 ms deadline that had to fire after the cleanup reached its held read. On a slow runner it fired first.withDeadlineandAppReset.runRemoteCleanupgain anuntil:overload that takes any deadline, not only a clock.ServerConnectionResetTestsandProfileDestinationViewTests: 3 s waits for a connection or operation to reach its gate failed when a starved main actor delayed it. In one CI run, a 100 ms sleep took 3.3 s. The gates now wait without a clock, and they fail at once if the operation ends without reaching the gate.PaykitPaymentRequestServiceTests:testSubscriptionRevalidatesAfterIconUploadBeforeEnqueuepolled for a paused upload for at most 2 s. It now polls until the upload pauses, and fails at once if the operation ends first.BackupService: a backup request made just before a wipe or restore began could reach the backup queue after it began. It then started a job and left the category marked running.testTemporaryFailureRemainsPendingAcrossServiceRestart, that left the restarted service's observer skipping the pending backup. The test failed about 1 in 200 runs.scheduleBackupnow drops such a request and clears the running flag thatmarkBackupRequiredset for it.unit-tests.yml: the job hit its one-hour limit when a slow runner's build took up to 36 minutes. No test was hanging.BitkitUITestsandBitkitUITestsLaunchTests. They asserted nothing and took about 9 minutes of each run: the launch test ran once per UI configuration (30 times), and the launch performance test alone took 99 s.Out of Scope
.github/workflows/unit-tests.yml: build caching for slow runners. The step timeout only bounds them.PaykitPaymentRequestServiceTests: the other users of the 2 swaitUntil(timeout:)helper, none of which failed in CI.ProfileDestinationViewTests: the remaining 3 s waits on lookup, restoration and profile fetch, none of which failed in CI.AppResetTestsandWalletViewModelWipeTests: their deadline-based tests, which did not fail in CI.Design
N/A — no UI changes.
Preview
N/A
QA Notes
Setup
N/A — no device testing required.
Journeys
N/A — no user-visible behaviour change.
Manual Tests
N/A
Automated Checks
UsdtWalletUITests.swift— USDT Receive opens USDT receive details once the wallet push ends, and the camera alert is dismissedPaykitSdkIdentityCheckTests.swift— an abandoned cleanup cannot reach the replacement wallet, whatever the runner's speedServerConnectionResetTests.swift— late connections after a reset are ignored, with no clock on reaching the gateProfileDestinationViewTests.swift— a deferred session keeps its public profile across recovery failures, with no clock on reaching the gatePaykitPaymentRequestServiceTests.swift— the subscription revalidates after the icon upload, however long the upload takes to pauseBackupServiceTests.swift— a temporary failure stays pending across a service restartBitkitUITests.swift— Xcode template with no assertionsBitkitUITestsLaunchTests.swift— Xcode template with no assertionsEvidence
All results below are on 11a40ce or its test-identical predecessors, on an iPhone 17 simulator with iOS 26.5.
testTemporaryFailureRemainsPendingAcrossServiceRestart: 2,000 of 2,000 runs passed. On master it failed about 1 in 200.BackupServiceTestsclass passed 3 times in a row.testReceiveAndInvalidPaymentStaySeparateFromBitcoin: 5 of 5 runs passed against staging regtest, none skipped.AndroidBackupJsonTestsfailed, because that run happened on a machine without the source checkout and the test reads its fixtures from the source path. With the fixtures present, all 6 of its tests passed.swiftformat --lintis clean on the changed files.Gaps
Models used
claude-opus-5-5(reasoning:10)claude-opus-5-5(reasoning:10)claude-sonnet-5-5(reasoning:10)