test(draft): de-flake fork-readiness retry test (fake only setTimeout + flush real async) - #1057
Conversation
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
|
Note 🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦 💡 Gittensory review — advisory only
💡 Advisory only — no action taken
💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers. |
ghost
left a comment
There was a problem hiding this comment.
Gittensory approves — the gate is satisfied.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1057 +/- ##
===========================================
+ Coverage 70.27% 95.39% +25.11%
===========================================
Files 148 148
Lines 17864 17864
Branches 6473 6473
===========================================
+ Hits 12554 17041 +4487
+ Misses 4118 359 -3759
+ Partials 1192 464 -728 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ke timers) The test drove an async flow — real WebCrypto token-decrypt + async D1/fetch interleaved with one setTimeout(sleep 3000) — via a fake-timer pump loop. Under CI full-shard coverage load the real macrotask lagged the microtask flush the pump relied on, so the scheduled sleep was never fired and the test HUNG → 15s timeout (the CI-only flake that blocked #1050/#1051/#1052/#1056). Fix: drop fake timers entirely. Mock setTimeout so the sleep(3000) backoff fires on a real 0ms tick, then await processSubmitDraft directly — the flow runs to completion on the real event loop (probe 404 → instant backoff → probe 200 → open PR) with no pump, no race, no real 3s wait, no weakened assertions. Verified stable across 6+ consecutive plain + coverage runs locally.
c3c8f1a to
e6e7226
Compare
ghost
left a comment
There was a problem hiding this comment.
Gittensory approves — the gate is satisfied.
Why
draft.test.ts > processSubmitDraft — fork-readiness retry loop (fake timers)flaked only in CI undertest:coverage --shard=1/2(passed locally + on re-run), repeatedly blocking thevalidategate on #1050, #1051, #1052, #1056.Root cause
The flow interleaves real async — WebCrypto token-decrypt (
crypto.subtle, a real macrotask) + the async D1/fetch mocks — with one fakesetTimeout(sleep 3000). The old driver pumpedawait vi.advanceTimersByTimeAsync(3000)in a fixed 50-iteration loop, which only flushes microtasks. Under coverage-instrumented slowness the crypto macrotask lagged, so thesleepwasn't scheduled before the loop exhausted its iterations →await donehung → CI timeout.Fix
setTimeout/clearTimeout(the sleep) viauseFakeTimers({ toFake: [...] }), so every other async — crypto, D1, fetch — runs on the real event loop.setImmediatemacrotask tick (lets the real chain complete + schedule its next sleep), then fire the one pending fake sleep, repeating until the flow settles.No weakened assertions, no real 3s wait. Verified stable across 8 consecutive runs (5 plain + 3 under coverage).