fix(server): clear auth cleanup intervals to prevent flaky test exits#5576
Conversation
The three `setInterval` timers in auth.ts (session cache, DB refresh, ban cache) were never cleared. When vitest exits while an interval callback is still in-flight, the worker can produce a corrupted response and flake the `require-admin-cross-tenant` test. Capture each timer handle from `startBackgroundCleanup` and export a `stopAuthTimers()` helper so test teardown can clear them cleanly. Closes adcontextprotocol#5393 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
IPR Policy Agreement Required@garvitkaushik-123 — thanks for the contribution. Before this PR can be merged, the AgenticAdvertising.Org IPR Policy requires your agreement. To agree, post a new comment on this PR with the exact phrase: Your signature is recorded once and covers all contributions to AAO repositories. See |
There was a problem hiding this comment.
The automated review encountered an issue (possibly reached max turns, timed out, or failed to post the final gh pr review). A human reviewer should take this PR.
This is an automated message from the Argus AI review workflow.
|
I have read the IPR Policy |
IPR Policy — signedThanks, @garvitkaushik-123. Your agreement to the IPR Policy is recorded at |
Summary
Fixes the flaky
require-admin-cross-tenant.test.tsthat fails under full-suite parallelism but passes in isolation (#5393).Root cause: The three
setIntervaltimers started bystartBackgroundCleanupinauth.ts(session cache, DB refresh, ban cache) are never cleared. When vitest exits while an interval callback is still in-flight, the worker can produce a corrupted response on the affected test.Fix:
startBackgroundCleanupnow returns the timer handle instead ofvoidstopAuthTimers()export callsclearIntervalon all threeafterAll(() => stopAuthTimers())for clean teardownNon-breaking — adds one optional export to
auth.ts, no protocol surface change.Test plan
vitest run server/tests/unit/require-admin-cross-tenant.test.ts— 16/16 passvitest run --no-file-parallelism server/tests/— full sequential suite to confirm the race is gonetsc --noEmit— compiles cleanCloses #5393