Files
Hendrik LiebauandGitHub 542b2b029c [test] Fix edge-async-local-storage deploy test timeout & race condition (#91643)
The test was calling `createNext` inside each `it.each` test body, which
meant deployment setup time counted against the 60-second per-test
timeout introduced in #89929. In deploy mode, `createNext` deploys to
Vercel which can exceed 60 seconds. When the test timed out, the `next`
local variable was never assigned (the `await createNext(...)` hadn't
resolved), so the `afterEach` hook would throw a `TypeError` on
`next.destroy()`. This left the module-level `nextInstance` variable
pointing at the stale, half-initialized deploy instance. When the next
test case started, `createNext` saw the leftover `nextInstance` and
threw `"createNext called without destroying previous instance"`.

The test now uses `nextTestSetup`, which runs `createNext` in
`beforeAll` where it has the longer 120-second `setupTimeout`. Both API
route variants (`/api/single` and `/api/multiple`) are real fixture
files served from a single instance, so deployment only happens once.
2026-03-20 09:37:42 +01:00

25 lines
736 B
JavaScript

export const config = { runtime: 'edge' }
// eslint-disable-next-line no-undef
const topStorage = new AsyncLocalStorage()
export default async function handler(request) {
const id = request.headers.get('req-id')
return topStorage.run({ id }, async () => {
const nested = await getSomeData(id)
return Response.json({ ...nested, ...topStorage.getStore() })
})
}
async function getSomeData(id) {
// eslint-disable-next-line no-undef
const nestedStorage = new AsyncLocalStorage()
return nestedStorage.run('nested-' + id, async () => {
try {
const response = await fetch('https://example.vercel.sh')
await response.text()
} finally {
return { nestedId: nestedStorage.getStore() }
}
})
}