Repository navigation
Clear armed reconnect timers in browser-sync-service test teardown - #2700
Conversation
BrowserSyncService.connect()'s catch block arms scheduleReconnect's indefinite-retry setTimeout on failure. The top-level afterEach reset stores and mocks but never called browserSyncService.destroy(), the only call that clears that timer, so a timer armed by one test could survive into another test file's run. One test in the Reconnection Logic block also swapped to real timers mid-test and only restored fake ones in a finally, without clearing any timer armed during that real-timer window — a real >=1000ms setTimeout that could fire while an unrelated test file was executing later in the suite, surfacing as a misattributed unhandled-error failure. Call destroy() in the top-level afterEach so no reconnect timer outlives its test, and destroy() explicitly in that test's finally block (while real timers are still active) before restoring fake timers. Closes #2684 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Code Review SummaryIndependent verification of the fix for #2684 (armed Root-cause claim verified against source (
Vitest hook-ordering claim verified: the top-level Test-file read directly (not just diffed): confirmed the "should handle EventSource creation error" test (lines 1016-1049) matches the issue's description exactly — No broken assertions: grepped every Findings🟢 Nitpick — issue text references a nonexistent method name. #2684's body suggests calling 🟢 Nitpick — redundant double No 🔴 Critical or 🟡 Improvement findings. The fix is minimal, targeted, matches the issue's own suggested fix, touches no production code, and doesn't paper over the underlying design (indefinite-retry reconnect is intentional/documented) — it just ensures tests actually tear down the service they exercise, which they always should have been doing. Full-suite verification (3x
|
mstomar125
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
Address-Review TriageReviewed the independent pragmatic-code-review above (verdict: APPROVE, 0 🔴 Critical, 0 🟡 Improvement, 2 🟢 Nitpicks).
Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: No code changes resulted from this review — both findings were informational nitpicks with no actionable follow-up, and the reviewer independently verified timer-teardown correctness, 47/47 isolated pass, and 3x clean full-suite runs before approving. Nothing new to re-verify. The PR is ready for merge. |
Problem
bun run test(full suite) intermittently failed with 1 failed test file / 1 failed test, reported as an unhandled error originating inBrowserSyncService.scheduleReconnect— a cross-file timing leak, not a genuine assertion failure.browser-sync-service.test.tsalways passed 47/47 in isolation.Root cause
BrowserSyncService'sconnect()catch block armsscheduleReconnect's indefinite-retrysetTimeouton failure (browser-sync-service.ts:180-181,:356-367). Two gaps let that timer escape the test that armed it:afterEachinbrowser-sync-service.test.tsreset stores/mocks but never calledbrowserSyncService.destroy()— the only call that clearsreconnectTimeout(:392-394). A timer armed anywhere in the file could survive teardown.Reconnection Logicblock (should handle EventSource creation error) swaps to real timers mid-test and only restores fake ones in afinally, without clearing any timer armed during that real-timer window. A reconnect armed there is a realsetTimeout(>=1000ms) that can fire while an unrelated test file is executing later in the suite, surfacing as a misattributed unhandled-error failure.Fix
browserSyncService.destroy()in the top-levelafterEachso no reconnect timer can outlive its test.destroy()explicitly in the real-timer test'sfinallyblock, beforevi.useFakeTimers()restores fake timers, so the real timer handle is cleared while realclearTimeoutis still in effect.Verification
browser-sync-service.test.tsstill passes 47/47 in isolation.mainfirst: 6 full-suite runs (~11 min), all green on the target flake (one unrelated, pre-existing perf-benchmark timing flake surfaced once, inarchitecture-benchmarks.test.ts, unaffected by this change). The intermittency matches the issue's own description — did not force a repro, deferred to the issue's already-solid root-cause diagnosis per task guidance.bun run test) passes clean on the fixed branch; pre-push gate (test:all,cargo build --bin nodespaced,test:e2e) passed clean.Closes #2684
🤖 Generated with Claude Code