Fix the session-build-semaphore timeout test flake - #1
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe semaphore timeout test now uses Vitest fake timers, restores real timers after each test, and asserts an exact 10ms timeout result. ChangesSemaphore timeout testing
Estimated code review effort: 1 (Trivial) | ~3 minutes Merge Risk: ⚪ Minimal · up to This test-only change makes the semaphore timeout assertion deterministic without changing production behavior; no actionable merge-blocking risk remains. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What failed
session-build-semaphore.test.ts› "proceeds without a slot when the queue wait exceeds the timeout":The test starts a real 10ms
setTimeout, waits for it to fire, and asserts thatDate.now()advanced by at least 10ms. Sometimes it only advances 9ms.Why
Node's
setTimeoutmeasures its delay from libuv's cached loop time, which is refreshed once per event-loop iteration, not from the momentsetTimeoutis called. Sync work done earlier in the same iteration (here, thePromise.allandexpectcalls beforeacquireBuildSlot(10)) is counted against the 10ms. So the timer can fire when only 9ms of wall-clock has passed sincerequestedAt. Reproduced locally on Node 22 at ~5 in 2000 runs. It is a timing flake in the test; the semaphore itself is fine.Fix
Drive the timeout with
vi.useFakeTimers()+vi.advanceTimersByTime(10)sowaitMsis exactly 10 every run, and reset to real timers inafterEach.No changeset:
@executor-js/cloudis private and the change is test-only.🤖 Generated with Claude Code