Repository navigation
test: fix flaky hfHubOfflineThrowsWithoutWaitingForStubbornProvider (hang guard opened the gate on cancel) - #101
Merged
Conversation
…ncelled Gate.openAfterHangGuard used try? around Task.sleep, so guardTask.cancel() made the sleep throw, the error was swallowed, and gate.open() ran. That released the stubborn provider while hfHubOfflineThrowsWithoutWaitingForStubbornProvider was about to assert finished.value == nil, so under CI load the provider had already set finished = true (main failed at ConformanceOfflineGuardTests.swift:213 on c029688 and 7a4d1d0). A cancelled guard now returns without opening the gate. Adds two deterministic tests: cancelling the guard leaves the gate shut (fails on the old helper), and the timeout path still opens it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Problem
Build and Test (macOS 15)fails on main (c029688,7a4d1d0) and on #100 atConformanceOfflineGuardTests.swift:213:finished.value == nil("the provider must still be blocked when the error is thrown") seestrue. The last green main run was71bff98.Cause
It is a test-helper bug, not a bug in
HubOfflineDownloader.Gate.openAfterHangGuardwrotetry? await Task.sleep(60s); gate.open(). The tests callguardTask.cancel()right after the download returns; cancelling makes the sleep throw,try?swallows it, andgate.open()runs at once. That releases the stubborn provider, which setsfinished = true, racing the next assertion. Under load the provider wins; on an idle machine it usually does not (40/40 local runs of the two gated tests passed before the fix, so it is not reproducible by repetition).Fix
A cancelled guard returns without opening the gate; only the timeout opens it (
do { try await Task.sleep } catch { return }).Tests
hangGuardDoesNotOpenTheGateWhenCancelled: deterministic. Fails on the old helper (Expectation failed: !gate.opened), passes with the fix.hangGuardOpensTheGateOnTimeout: the timeout path still opens the gate.ConformanceOfflineGuardsuite: 19 tests pass; 30 further local runs, 0 failures.Test-only change; no library code is touched.
🤖 Generated with Claude Code