test: make the timeout-wins race deterministic under fake timers

CI (node 24/26) failed on the exact-boundary construction: advanceTimersByTime(100)
then an immediate upstream.abort() let the manual abort win the race on some
runtimes, so timeoutOf returned undefined. Advance unambiguously past the deadline
and assert the timeout classification before firing the late abort — that late
abort is now asserted as a no-op, which is the real first-cause-wins invariant.
This commit is contained in:
Dudu-0223
2026-07-06 19:55:46 +08:00
parent 208123f252
commit 6beed9a883
+5 -1
View File
@@ -99,7 +99,11 @@ describe('deadline — fuse with upstream', () => {
try {
const upstream = new AbortController()
using d = deadline(upstream.signal, 100, 'WEB_FETCH_TIMEOUT')
vi.advanceTimersByTime(100) // timer fires first
vi.advanceTimersByTime(150) // past the 100ms deadline: the timer fires first
expect(d.signal.aborted).toBe(true)
expect(timeoutOf(d.signal)?.code).toBe('WEB_FETCH_TIMEOUT')
// A later upstream abort is a no-op on the already-aborted fused signal:
// AbortSignal.any keeps the FIRST cause, so the timeout classification stands.
upstream.abort('too late')
expect(timeoutOf(d.signal)?.code).toBe('WEB_FETCH_TIMEOUT')
} finally {