Skip to content

test: give middleware auth guard assertion a CI-safe timeout - #2720

Merged
james-elicx merged 2 commits into
cloudflare:mainfrom
NathanDrake2406:nathan/unit-test-timeout
Jul 27, 2026
Merged

test: give middleware auth guard assertion a CI-safe timeout#2720
james-elicx merged 2 commits into
cloudflare:mainfrom
NathanDrake2406:nathan/unit-test-timeout

Conversation

@NathanDrake2406

@NathanDrake2406 NathanDrake2406 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #2719.

Root cause

The development-server auth-guard assertion in middleware-matcher-auth.test.ts performs a cold compile while issuing requests across every supported matcher shape. Its setup hook already had a 30-second timeout, but the assertion itself inherited Vitest's 5-second unit-test default.

That assertion exceeded the default on CI in run 30242579875:

tests/middleware-matcher-auth.test.ts:150
Error: Test timed out in 5000ms.

Under a full local unit 3/3 shard it completed in roughly 2.3 seconds, leaving too little margin for normal runner and cold-compile variance.

Fix

Give only that integration-style assertion an explicit 30_000 timeout, matching the existing timeout on its dev-server setup hook and the repository's convention for long-running tests.

The unit project's 5-second default remains unchanged. This avoids extending the hang/performance-regression window for the thousands of ordinary unit tests that do not boot a server.

Verification

  • vp test run --project unit tests/middleware-matcher-auth.test.ts: 27 passed
  • vp check tests/middleware-matcher-auth.test.ts vite.config.ts: clean
  • Full unit 3/3 shard forced to the original 5-second default: 2,219 passed, 1 skipped locally; the affected assertion completed in roughly 2.3 seconds.

The unit project set no `testTimeout`, so it inherited vitest's 5s default
while holding 47 files that boot a dev server or run a production build. 39 of
those pass a per-test timeout (up to 180_000); the ones that did not sat on a
~20% margin — `middleware-matcher-auth.test.ts`'s auth-guard case measures 4.0s
under normal parallel load — which ordinary CI variance erases. It and
`typegen.test.ts` each failed a different CI run that way while passing locally.

Adopts the 30000 the integration project already declares. A timeout costs
wall-clock only when a test hangs, so nothing that passes slows down, and
per-test arguments still take precedence.

Closes cloudflare#2719
@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vinext/cloudflare@2720
npm i https://pkg.pr.new/create-vinext-app@2720
npm i https://pkg.pr.new/@vinext/types@2720
npm i https://pkg.pr.new/vinext@2720

commit: 2abd661

@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared 2abd661 against base 05eee9f using alternating same-runner rounds. Next.js was unchanged and skipped.

0 improved · 0 regressed · 6 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 132.4 KB 132.4 KB ⚫ -0.0%
Client entry size (gzip) vinext 119.7 KB 119.7 KB ⚫ +0.0%
Dev server cold start vinext 3.06 s 3.05 s ⚫ -0.3%
Production build time vinext 3.03 s 3.03 s ⚫ +0.0%
RSC entry closure size (gzip) vinext 103.3 KB 103.3 KB ⚫ -0.0%
Server bundle size (gzip) vinext 177.8 KB 177.8 KB ⚫ -0.0%

View detailed results and traces

🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head

@james-elicx james-elicx changed the title test: give the unit project the integration timeout test: give middleware auth guard assertion a CI-safe timeout Jul 27, 2026
@james-elicx

Copy link
Copy Markdown
Member

/bigbonk review for issues

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

The change is minimal, correct, and well-reasoned. I verified the root-cause claim: tests/middleware-matcher-auth.test.ts is not listed in the integration project's include array in vite.config.ts (lines 247-288), so it runs under the unit project, which has no testTimeout override and therefore inherits Vitest's 5000ms default. Only the integration project sets testTimeout: 30000 (vite.config.ts:289).

The fix is scoped correctly:

  • The development server block (line 150) does a lazy cold compile during the requests — its beforeAll only calls startFixtureServer with no pre-build (lines 136-143). This is the assertion that can exceed 5s, so giving it 30_000 is the right target.
  • The Node (line 194) and Cloudflare Worker (line 263) blocks pre-build in beforeAll (with 120_000 / 180_000 hook timeouts), so their assertions are fast and correctly left at the default.
  • 30_000 matches the dev block's own beforeAll hook timeout (line 143) and the repo's integration-timeout convention.

The test uses createIsolatedFixture (mkdtemp-based isolated dirs), so it does not hit the shared-fixture deps-optimizer race that motivates the serial integration project — it legitimately belongs in the unit project.

LGTM. One optional observation below.

it("blocks every path selected by group and constrained-repeat matchers", async () => {
await assertAuthGuard(baseUrl);
});
}, 30_000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: consider hoisting the 30_000 into a shared const (e.g. const DEV_ASSERT_TIMEOUT = 30_000;) reused by both this assertion and its beforeAll hook on line 143, so the two stay coupled if either is tuned later. Not blocking — the inline literal is fine and matches the existing style in this file.

@ask-bonk

ask-bonk Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review posted successfully.

Summary

I reviewed PR #2720, which adds a 30_000 timeout to the dev-server auth-guard assertion in tests/middleware-matcher-auth.test.ts.

Verdict: LGTM. The change is a correct, minimal, and well-scoped one-line fix.

Key findings I verified:

  • Root cause is accurate. The test file is not in the integration project's include list in vite.config.ts, so it runs under the unit project — which has no testTimeout override and inherits Vitest's 5000ms default. Only the integration project sets testTimeout: 30000.
  • Fix targets the right assertion. The dev-server block (line 150) does a lazy cold compile during requests — its beforeAll only starts the fixture server with no pre-build. The Node (line 194) and Worker (line 263) blocks pre-build in beforeAll, so their assertions are fast and correctly left at the default.
  • Value is consistent. 30_000 matches the dev block's own beforeAll hook timeout and repo convention.
  • No hidden regression risk. The test uses createIsolatedFixture (mkdtemp-based isolated dirs), so it doesn't hit the shared-fixture deps-optimizer race that motivates the serial integration project — it belongs in the unit project as-is.

I left one optional, non-blocking suggestion to hoist 30_000 into a shared const reused by the assertion and its beforeAll hook.

github run

@james-elicx
james-elicx merged commit cfcd60b into cloudflare:main Jul 27, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky unit tests: server-booting tests run on vitest's default 5s timeout

2 participants