Repository navigation
Harden timing-sensitive tests against parallel-execution flakiness - #214
Merged
Merged
Conversation
Swift Testing runs tests in parallel by default, which exposed latent timing fragility in three tests on slow, contended CI simulators (these tests passed reliably under XCTest's serial execution): - `testWaitFor`: the updates were scheduled relative to the test's start, so a delayed `wait(for:)` subscription could miss them. Schedule a single update right before the wait instead, delayed so it lands after the wait starts observing. - `testWaitForUpdateWithinTimeout`: the success case used a tight 1s timeout that a contended host could exceed. Use a generous timeout so it only fails if the update never arrives. - `testComplexDependencies`: the test and the atom shared a single stream to hand off control in both directions, so the atom could consume its own signal from the shared buffer and proceed before the test updated a dependency. Use two one-way channels so neither side consumes the other's signal. Verified by reproducing the original flakiness under CPU contention (old tests failed, hardened tests passed across many runs). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens three timing-sensitive tests that became flaky after migrating to Swift Testing (parallel execution by default). The changes are confined to test code and aim to remove scheduling/race assumptions that break under CI contention (notably on slower simulators like watchOS).
Changes:
- Updated
AtomTestContextTests.testWaitForto schedule a single delayed state update immediately before the wait, reducing sensitivity to startup scheduling delays. - Increased the success-path timeout in
AtomTestContextTests.testWaitForUpdateWithinTimeoutto avoid spurious failures on contended hosts. - Refactored
StoreContextTests.testComplexDependenciesto use two one-way async channels to prevent test/atom signal cross-consumption under load.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Tests/AtomsTests/Core/StoreContextTests.swift | Replaces a shared stream pipe with two one-way pipes to remove a race in the test’s coordination protocol. |
| Tests/AtomsTests/Context/AtomTestContextTests.swift | Adjusts timing/timeout behavior in async wait tests to reduce parallel-execution flakiness. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Three tests flaked intermittently on CI after the migration to Swift Testing, which runs tests in parallel by default. On slow, contended simulators (especially watchOS) the parallel execution starved timing-sensitive async work, surfacing latent fragility that was masked by XCTest's serial execution. The failing tests don't depend on the change being a behavior regression — they fail purely due to scheduling delays under load.
This PR hardens the three tests. No production code changes.
Changes
testWaitFor(AtomTestContextTests): the updates were scheduled relative to the test's start, so if thewait(for:)subscription was delayed past all of them, the predicate was already satisfied and the wait returnedfalse. Now a single update is scheduled right before the wait and delayed so it lands after the wait starts observing — its timing is independent of the test's start.testWaitForUpdateWithinTimeout(AtomTestContextTests): the success case used a tightwithin: 1timeout that a contended host could exceed. It now uses a generous timeout, so it only fails if the update never arrives. The timeout-throwing case keeps its small timeout (it deterministically times out because no update happens).testComplexDependencies(StoreContextTests): the test and the atom used a single stream to hand off control in both directions. Under load the atom could consume its own signal from the shared buffer and proceed before the test updated a dependency (causing e.g.after == 0instead of1). It now uses two one-way channels (reachedSuspension,resume) so neither side consumes the other's signal.Verification
Reproduced the original flakiness by running the suite under CPU contention: the old tests failed intermittently (e.g.
testComplexDependencies), while the hardened tests passed across many runs, including under heavy load (2× cores of CPU stress).make format/make lintclean.🤖 Generated with Claude Code