Răsfoiți Sursa

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.
Dudu-0223 2 luni în urmă
părinte
comite
6beed9a883
1 a modificat fișierele cu 5 adăugiri și 1 ștergeri
  1. 5 1
      packages/util/timeout/tests/timeout.spec.ts

+ 5 - 1
packages/util/timeout/tests/timeout.spec.ts

@@ -99,7 +99,11 @@ describe('deadline — fuse with upstream', () => {
     try {
     try {
       const upstream = new AbortController()
       const upstream = new AbortController()
       using d = deadline(upstream.signal, 100, 'WEB_FETCH_TIMEOUT')
       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')
       upstream.abort('too late')
       expect(timeoutOf(d.signal)?.code).toBe('WEB_FETCH_TIMEOUT')
       expect(timeoutOf(d.signal)?.code).toBe('WEB_FETCH_TIMEOUT')
     } finally {
     } finally {