Skip to content

test: make ExampleBlocking and Delay GetWait test deterministic - #94

Merged
adrianbrad merged 2 commits into
mainfrom
fix/92-deterministic-blocking-example
Nov 7, 2026
Merged

adrianbrad merged 2 commits into
mainfrom
fix/92-deterministic-blocking-example

Conversation

@adrianbrad

Copy link
Copy Markdown
Owner

ExampleBlocking asserted on a wall-clock measurement (received after 1ms), which Windows timer overshoot rounds to 2ms; it also Peeked after Offer while the woken GetWait goroutine raced for the lock, which lost about 1 in 20000 runs locally at GOMAXPROCS=10. The example is rewritten with no timing at all: Peek runs while the initial head is present, Get is shown erroring on the empty queue, and GetWait hands its element back over a channel, so the output no longer depends on scheduling. Stress-testing the suite also exposed TestDelay/GetWait/WakesAfterDeadline measuring elapsed time from a second clock reading taken after the deadline was computed, which fails under load by a few microseconds; it now compares the return time to the deadline itself. The queue code is untouched.

Verified locally with 40 full-suite runs under race, shuffle and atomic coverage with four busy loops competing for CPU: 0 failures, down from 2 in 15 before the Delay fix. Coverage stays at 100%.

A second, non-blocking CI job now runs the race-enabled suite on windows-latest and macos-latest, so this PR's own checks are the first Windows verification of the fix. The required Test job is unchanged.

Closes #92

adrianbrad and others added 2 commits November 7, 2026 17:21
…Wait

ExampleBlocking printed the goroutine's measured wait rounded to the
millisecond and expected exactly "1ms". The value is sleep plus wake-up
latency, so on Windows, where Sleep overshoots by half a millisecond or
more, it rounds to "2ms" and the example fails (#92). It also Peeked
after Offer while a woken GetWait goroutine raced for the lock; under
GOMAXPROCS=10 Peek observed an empty queue about 1 in 20000 runs.

Rewrite the example without timing: Peek while the initial head is
present, show Get erroring on the empty queue, then show GetWait
receiving the offered element through a channel. The output is now
independent of scheduling.

TestDelay/GetWait/WakesAfterDeadline measured elapsed time from a clock
reading taken after the deadline was computed, so under load it could
fall a few microseconds short of 20ms although GetWait woke on time
(2/15 failures with atomic coverage under CPU contention). Compare the
return time against the deadline itself instead.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The coverage job stays Linux-only; a separate non-blocking matrix job
runs the race-enabled suite on windows-latest and macos-latest so
platform-specific timing and scheduler differences surface in CI
instead of in contributors' local runs (#92).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (19a6248) to head (291e3e3).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #94   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          552       552           
=========================================
  Hits           552       552           
Flag Coverage Δ
unittests 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adrianbrad
adrianbrad merged commit 2e0bc1c into main Nov 7, 2026
12 checks passed
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.

ExampleBlocking elapsed-time output varies on Windows

1 participant