Skip to content

Commit 3810acc

Browse files
committed
fix(tests): handle the cancelled token-sealing run's rejection before polling for its backend
The operator-cancel test started migrate() and only attached a handler after its pg_cancel_backend polling loop. When the cancellation reached the run's connection before the loop broke, Node saw an unhandled rejection and Vitest failed the whole db shard even though every test passed. Attach the rejection assertion when the run starts and await it after the loop.
1 parent 7c829c1 commit 3810acc

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎packages/db/script-migrations/0037_seal_account_tokens.integration.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ describe('sealing stored account tokens in PostgreSQL', () => {
358358
await insertAccount('cancelled-access', 'cancelled-refresh')
359359
await onAccountUpdate('PERFORM pg_sleep(20)')
360360

361-
const run = migrate()
361+
/** Handled from the start: the cancel can fail the run before the polling loop sees it. */
362+
const failed = expect(migrate()).rejects.toThrow('canceling statement due to user request')
362363
for (let attempt = 0; attempt < 100; attempt++) {
363364
const [cancelled] = await admin<{ cancelled: boolean }[]>`
364365
SELECT pg_cancel_backend(pid) AS cancelled FROM pg_stat_activity
@@ -368,7 +369,7 @@ describe('sealing stored account tokens in PostgreSQL', () => {
368369
await sleep(50)
369370
}
370371

371-
await expect(run).rejects.toThrow('canceling statement due to user request')
372+
await failed
372373
expect(await isRecorded()).toBe(false)
373374
expect((await storedRows())[0].access_token).toBe('cancelled-access')
374375
}, 30_000)

0 commit comments

Comments
 (0)