test(js): fix flaky load fail-fast tests on slow CI runners#9171
Conversation
…timers The pumpUntilSettled helper advanced fake time on a fixed budget, but load() awaits native crypto (cookie suffix) before scheduling its initialization timeout. On slow CI runners the crypto work resolves after all pump iterations have drained, leaving the fake timer unadvanced and the test hung until vitest's 5s testTimeout. Yield real event-loop turns until a fake timer is actually scheduled (or load settles) before spending the advance budget. Reproduced deterministically by delaying crypto.subtle.digest by 200ms: the two CI-flaky tests fail with the old helper and pass with the new one. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 50398eb The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Repository UI (inherited) Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR updates ChangesLoad test timer handling
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/electron
@clerk/electron-passkeys
@clerk/eslint-plugin
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
API Changes Report
Summary
No API Changes DetectedAll packages have stable APIs with no detected changes. Report generated by Break Check Last ran on |
Description
The fake-timer tests added in #9065 (
describe: "when the client fetch fails or hangs at load") are flaking across unrelated PRs — two 5s timeouts on run 29305425991 and run 29413333718.The race:
load()awaits native crypto for the cookie suffix beforetimeLimit()schedules its initialization timer.pumpUntilSettledadvanced fake time on a fixed 20-iteration budget, butcrypto.subtle.digestresolves on the real event loop — fake timers can't move it. On a slow runner the digest lands after all 20 pumps have drained, the 7s fake timer sits unadvanced forever, and vitest's 5stestTimeoutkills the test. That's why CI failures always report ~5015ms and local runs finish in ~17ms.The fix teaches
pumpUntilSettledto yield real event-loop turns until a fake timer is actually scheduled (or the promise settles) before spending its advance budget. No runtime code changes.To verify, I reproduced the race deterministically by delaying
crypto.subtle.digestby 200ms: exactly the two CI-flaky tests fail with the old helper, and all pass with the new one. The full file then passed 5 consecutive runs, plus 3 more with all cores saturated by busy loops.Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
🤖 Generated with Claude Code
Summary by CodeRabbit