From 7cdabbcc63c727ac00124453dd403611df200d25 Mon Sep 17 00:00:00 2001 From: Brian O'Kelley Date: Thu, 1 Oct 2026 12:36:56 +0000 Subject: [PATCH] test(auth): replace 50ms deletion-race deadlines with a settle check Two deletion-race tests held post-commit side effects, slept 50ms, and asserted deletion had already settled. Deletion runs several real Postgres transactions, so a slow CI runner failed the assertion even though deletion was never blocked (main run 36850679984). Await deletion with the file's 5s within() deadline while the side effects are still held, releasing them in finally. A deletion that does wait on post-commit work still fails, with "race did not settle". Co-Authored-By: Claude Opus 5.5 (1M context) --- .../workos-user-deletion-race.test.ts | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/server/tests/integration/workos-user-deletion-race.test.ts b/server/tests/integration/workos-user-deletion-race.test.ts index 2f27d6290f2..75f644186e6 100644 --- a/server/tests/integration/workos-user-deletion-race.test.ts +++ b/server/tests/integration/workos-user-deletion-race.test.ts @@ -709,15 +709,17 @@ describe('WorkOS webhook vs sync-users deletion', () => { updated_at: new Date().toISOString(), })); await entered; - let deletionSettled = false; - const deletion = deleteIdentityCredential(PRIMARY, 'workos_webhook') - .finally(() => { deletionSettled = true; }); - await new Promise((resolve) => setTimeout(resolve, 50)); - const deletionWasBlocked = !deletionSettled; - releaseSideEffects(); - const [eventResponse, deletionResult] = await within(Promise.all([staleUserEvent, deletion])); + // Post-commit side effects are still held, so deletion can only settle if + // it does not wait on them. A generous deadline instead of a fixed sleep + // keeps slow runners from failing a deletion that is merely slow. + let deletionResult: Awaited>; + try { + deletionResult = await within(deleteIdentityCredential(PRIMARY, 'workos_webhook')); + } finally { + releaseSideEffects(); + } + const eventResponse = await within(staleUserEvent); - expect(deletionWasBlocked).toBe(false); expect(eventResponse.status).toBe(200); expect(deletionResult.deleted).toBe(true); expect((await pool.query(`SELECT 1 FROM users WHERE workos_user_id = $1`, [PRIMARY])).rows).toEqual([]); @@ -800,15 +802,15 @@ describe('WorkOS webhook vs sync-users deletion', () => { WHERE workos_user_id = $1 AND workos_organization_id = $2`, [PRIMARY, ORG], )).rows; - let deletionSettled = false; - const deletion = deleteIdentityCredential(PRIMARY, 'workos_webhook') - .finally(() => { deletionSettled = true; }); - await new Promise((resolve) => setTimeout(resolve, 50)); - const deletionWasBlocked = !deletionSettled; - releasePostWrite(); - const [eventResponse, deletionResult] = await within(Promise.all([staleMembershipEvent, deletion])); + // As above: deletion must settle while post-commit work is still held. + let deletionResult: Awaited>; + try { + deletionResult = await within(deleteIdentityCredential(PRIMARY, 'workos_webhook')); + } finally { + releasePostWrite(); + } + const eventResponse = await within(staleMembershipEvent); - expect(deletionWasBlocked).toBe(false); expect(membershipWhileLocked).toEqual([{ role: 'admin' }]); expect(eventResponse.status).toBe(200); expect(deletionResult.deleted).toBe(true);