diff --git a/__tests__/server/stores.test.ts b/__tests__/server/stores.test.ts index 7f8418b7..8534e315 100644 --- a/__tests__/server/stores.test.ts +++ b/__tests__/server/stores.test.ts @@ -221,7 +221,17 @@ describe('the server with stores', () => { const port = 21000 + Math.floor(Math.random() * 1000) const { passthrough } = await import('msw') server.use(http.all(`http://127.0.0.1:${port}/*`, () => passthrough())) - server.use(http.post(`${api}/app/installations/7/access_tokens`, () => new Promise(() => {}))) + // @octokit/auth-app shares one pending-request map per installation across every + // createAppAuth in the process, so a token request this test never answered would + // hang the next test of this file that mints a token for installation 7 + let abandonToken!: () => void + const tokenHeld = new Promise((resolve) => { + abandonToken = resolve + }) + server.use(http.post(`${api}/app/installations/7/access_tokens`, async () => { + await tokenHeld + return new Response('abandoned by the test', { status: 500 }) + })) const listening = main({ ...env, PORT: String(port), PROW_SHUTDOWN_GRACE_MS: '30' }, signals) try { await listening.ready @@ -234,6 +244,9 @@ describe('the server with stores', () => { await vi.waitFor(() => expect(exit).toHaveBeenCalledWith(0)) } finally { + abandonToken() + await vi.waitFor(() => expect(write.mock.calls.map(call => JSON.parse(String(call[0])) as { level: string })).toContainEqual(expect.objectContaining({ level: 'error' }))) + await listening.close(0) write.mockRestore() } }) diff --git a/docs/contributing.md b/docs/contributing.md index 14174d57..8a615c77 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -125,7 +125,7 @@ range of its own, is counted correctly. Vitest runs the tests of a file in source order, so a test that leaves state behind is only noticed by the tests that happen to follow it. `npm run test:shuffle` runs every file's tests in a random order (the seed is printed -with the failure; `--sequence.seed=` repeats it). The three ways a test has +with the failure; `--sequence.seed=` repeats it). The four ways a test has leaked into its neighbour here, and how each file now avoids them: - **A mutated fixture.** The JSON fixtures are imported once per file, so @@ -151,6 +151,16 @@ leaked into its neighbour here, and how each file now avoids them: `utils.newRun()`. A file that uses `vi.resetModules()` must import `@actions/core` and the module under test fresh together, or the assertion spies on a different `core` instance than the one the module warns through. +- **An installation-token request that never settles.** `@octokit/auth-app` + deduplicates concurrent token requests for one installation in a map that is + shared by every `createAppAuth` in the process, not one per App. An msw + handler for `POST /app/installations/{id}/access_tokens` that returns a + promise which never resolves therefore parks every later mint for that + installation in the same file, however many receivers the tests build — the + next test that mints a token hangs until its timeout without issuing a + request. Hold the handler on a promise the test settles in its `finally` + (a 500 ends the delivery with no further requests), and wait for the parked + delivery's failure line before restoring the spies it logs through. ### Mutation checks