Skip to content

test: fix flaky unit and ui tests - #1327

Merged
ovitrif merged 1 commit into
masterfrom
fix/flaky-unit-tests
Nov 13, 2026
Merged

ovitrif merged 1 commit into
masterfrom
fix/flaky-unit-tests

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

This PR makes the Run Tests check 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: testReceiveAndInvalidPaymentStaySeparateFromBitcoin had two failure modes.
    • It tapped USDT Receive while the wallet screen was still being pushed. Home's own Receive button was then under the tap, which opened Bitcoin Receive. The test now waits until Home's Receive is gone and USDT Receive is hittable.
    • A tap on the camera alert's Allow, made while the alert was still animating in, could be dropped, leaving the alert up. The test now waits until Allow is hittable, and taps again if the alert is still there 2 s later.
  • 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.
    • withDeadline and AppReset.runRemoteCleanup gain an until: overload that takes any deadline, not only a clock.
    • The test now ends the wipe's wait once the cleanup is held in its read.
  • ServerConnectionResetTests and ProfileDestinationViewTests: 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: testSubscriptionRevalidatesAfterIconUploadBeforeEnqueue polled 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.
    • In testTemporaryFailureRemainsPendingAcrossServiceRestart, that left the restarted service's observer skipping the pending backup. The test failed about 1 in 200 runs.
    • In the app, it could keep a category from being scheduled again for the rest of the session.
    • scheduleBackup now drops such a request and clears the running flag that markBackupRequired set for it.
    • The test also gives each category its own defaults suite.
  • 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.
    • The test step now has a 55-minute timeout, which leaves time for the results upload.
    • Each test gets a 300 s execution-time allowance, so a hung test fails on its own instead of stalling the run.
  • Removed Xcode's template UI tests BitkitUITests and BitkitUITestsLaunchTests. 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 s waitUntil(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.
  • AppResetTests and WalletViewModelWipeTests: 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

  • updated UsdtWalletUITests.swift — USDT Receive opens USDT receive details once the wallet push ends, and the camera alert is dismissed
  • updated PaykitSdkIdentityCheckTests.swift — an abandoned cleanup cannot reach the replacement wallet, whatever the runner's speed
  • updated ServerConnectionResetTests.swift — late connections after a reset are ignored, with no clock on reaching the gate
  • updated ProfileDestinationViewTests.swift — a deferred session keeps its public profile across recovery failures, with no clock on reaching the gate
  • updated PaykitPaymentRequestServiceTests.swift — the subscription revalidates after the icon upload, however long the upload takes to pause
  • updated BackupServiceTests.swift — a temporary failure stays pending across a service restart
  • removed BitkitUITests.swift — Xcode template with no assertions
  • removed BitkitUITestsLaunchTests.swift — Xcode template with no assertions

Evidence

All results below are on 11a40ce or its test-identical predecessors, on an iPhone 17 simulator with iOS 26.5.

  • Reproduction: I injected delays matching the CI logs.
    • On master's tests, the four timing tests failed with the same messages as CI.
    • With this PR's tests and the same delays, all four passed.
  • Fixed unit tests, 20 runs each: 280 of 280 cases passed.
  • testTemporaryFailureRemainsPendingAcrossServiceRestart: 2,000 of 2,000 runs passed. On master it failed about 1 in 200.
    • The whole BackupServiceTests class passed 3 times in a row.
  • testReceiveAndInvalidPaymentStaySeparateFromBitcoin: 5 of 5 runs passed against staging regtest, none skipped.
  • Unit suite with CI's skip list: 3,935 tests ran, 4 skipped. Only AndroidBackupJsonTests failed, 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.
  • Lint: swiftformat --lint is clean on the changed files.

Gaps

  • The step timeout and the per-test allowance have not been triggered on a real CI runner yet. This PR's own CI run is the first check of the workflow change.

Models used

  • Planning/scoping: claude-opus-5-5 (reasoning: 10)
  • Implementation: claude-opus-5-5 (reasoning: 10)
  • Review: claude-sonnet-5-5 (reasoning: 10)
  • Review rounds: 1

@ovitrif ovitrif self-assigned this Nov 13, 2026
@ovitrif
ovitrif requested review from a team, ben-kaufman and pwltr and removed request for a team November 13, 2026 10:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T10:27:10.206932Z 11a40ce PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge; no actionable issues were found.

Summary

This PR replaces timing-sensitive test waits with gates, waits for USDT controls before tapping, and removes template UI tests.

  • Backup requests no longer stay marked running through a wipe or restore.
  • The wallet-cleanup test waits for the held read before ending the wipe.
  • Tests wait for an operation to reach its gate instead of racing a short timer.
  • USDT UI tests wait until wallet controls are ready to tap.
  • The test workflow limits how long each test run can stall.
  • The empty Xcode template UI tests no longer run.

Acknowledgments: ovitrif explicitly describes the clock-free waits as intentional. ovitrif also defers build caching, other payment-request polling waits, remaining profile waits, and deadline-based tests outside this change.

Reviews (1) · Last reviewed commit: "test: fix flaky unit and ui tests" · Reviewed by Greptile

@talosmachina talosmachina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 scheduleBackup clears running under a live upload: it clears only when backupJobs and runningBackupTasks are both empty for the category, read on the same .backup queue that registers them, so an in-flight triggerBackup or retry keeps its flag and clears it itself at the end of runBackup.
  • Clearing running re-triggers the observer during the wipe: the per-category publisher dedupes on synced and required only, and the sink checks shouldSkipBackup first. After a restore, scheduleFullBackup sees isRequired && !running and schedules, which is the stuck case the PR describes.
  • Moving shouldSkipBackup ahead of the foreground-generation guard changes the foreground path: on that path runBackup has already reset running and removed its task before scheduleBackup runs, so the earlier return only adds a redundant running: 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, so reachedWaiter is set inside withCheckedContinuation before the watcher can run. ProfileOperationGate buffers true in 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 pwltr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ovitrif

ovitrif commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

Merging: approved on 11a40ce, CI green, no open threads.

@ovitrif
ovitrif merged commit c8fafb7 into master Nov 13, 2026
21 checks passed
@ovitrif
ovitrif deleted the fix/flaky-unit-tests branch November 13, 2026 12:29
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.

3 participants