Deflake queue-deallocation tests by awaiting the enqueued task#78
Open
dfed wants to merge 1 commit into
Open
Conversation
The four `*_executesAfterQueueIsDeallocated` tests confirmed the final enqueued task ran by waiting on `Expectation.fulfillment(withinSeconds: 30)`. That is a wall-clock race: the expectation pits a `Task.sleep(30s)` against `fulfill()`, and `fulfill()` itself hops through an extra detached task. Under the `-test-iterations 100 -run-tests-until-failure` stress harness on a slow, contended simulator (visionOS), the cooperative pool can be starved long enough that the sleep wins before the queued work is scheduled, producing a false failure. `Task(on:)` captures only its `Delivery`/`Semaphore` — never the `FIFOQueue` — so holding the returned handle does not retain the queue, and the `weak queue == nil` assertion still holds. Capture the last enqueued task and `await` its value instead. This removes the wall-clock race entirely and is a strictly stronger check: it waits for the work to actually complete rather than for a side-channel flag, while the `Counter` assertions still verify ordering. The tests now finish in ~1ms regardless of runner speed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #78 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 13 13
Lines 1301 1297 -4
=========================================
- Hits 1301 1297 -4
🚀 New features to boost your workflow:
|
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.
What
Rewrite the four
*_executesAfterQueueIsDeallocated()tests inFIFOQueueTeststoawaitthe final enqueued task's value instead of waiting onExpectation.fulfillment(withinSeconds: 30).Why
These tests were the source of the intermittent
visionOS_2CI failures (Expectation not fulfilled within 30 seconds, e.g. iteration 8/100). The expectation is a wall-clock race: it pits aTask.sleep(30s)againstfulfill(), andfulfill()itself hops through an extra detachedTask. Under the-test-iterations 100 -run-tests-until-failurestress harness on a slow, contended simulator, the cooperative pool can be starved long enough that the sleep wins before the queued work runs — a false failure. The identical code passes on macOS/iOS/Linux; it's purely runner-speed sensitivity.How it stays correct
Task(on:)captures only itsDelivery/Semaphore, never theFIFOQueue, so holding the returned handle doesn't retain the queue — theweak queue == nilassertion still holds. Awaiting the last enqueued task is a strictly stronger check than the old expectation: it waits for the work to actually complete rather than for a side-channel flag, and theCounterassertions still verify execution order. Tests now complete in ~1ms regardless of runner speed.The other
fulfillment(withinSeconds:)call sites (e.g.ExpectationTests, which deliberately tests timeout behavior) are left unchanged.🤖 Generated with Claude Code