Repository navigation
Keep the event loop alive in withMCPAuth's getUser-timeout test - #289
Conversation
withMCPAuth's user-lookup timer is unref()'d and this test's getUser never settles, so on Node 22 nothing holds the event loop open until the 20 ms timeout fires; the runner then cancels the test and every later test in the file. Hold a referenced interval for the duration of the await. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request updates the test suite in test/lib/mcp/withMCPAuth.test.js to prevent the test runner from prematurely cancelling a test. It introduces a temporary setInterval keep-alive mechanism around the withMCPAuth call to keep the event loop active while waiting for a timeout to fire, clearing the interval in a finally block. There are no review comments to address.
|
Reviewed; no blockers found. The fix correctly addresses a race between the Node 22 test runner and the unref'd timeout in |
Summary
The getUser-timeout test (
test/lib/mcp/withMCPAuth.test.js, added in #287) cancels on Node 22, along with every later test in the file. On the release PR (#288) it made Lint, Build & Test (22) fail twice: 23 tests cancelled, Promise resolution is still pending but the event loop has already resolved.Cause:
withMCPAuthunref()s its user-lookup timer (src/lib/mcp/withMCPAuth.ts:261), which is correct for a server. This test'sgetUserreturns a promise that never settles. So once the request is waiting, nothing referenced keeps the event loop alive until the 20 ms timeout fires, and Node 22's test runner treats the drained loop as a hung test. On Node 24 and 26 something else happens to hold the loop open, so it passes there.Fix: test-only. Hold a referenced
setIntervalfor the duration of the await, and clear it infinally. Production code is unchanged.Verification
Single test,
--test-name-pattern="when getUser times out":The full suite under coverage on Node 22.23.1, as CI runs it, gives 1877 pass, 0 fail, 0 cancelled. Node 24 is unchanged.
Unblocks the 2.10.0 release (#288).
🤖 Generated with Claude Code