redis - test: Stop the keep-alive test from racing the connect timeout - #2193
Merged
Merged
Conversation
"should keep a successful connection alive after connectionTimeout elapses" connected to a real Redis with `connectionTimeout: 50`, so the TCP connect and the handshake had 50 ms to finish. Under the parallel test load in CI they sometimes take longer, the connect times out, and the test fails with "Redis timed out after 50ms". That happened in the codecov job on main at 6d4b270 and on #2192. The test now uses 500 ms, the budget the other tests that connect to a real server use, and waits 600 ms instead of 120 ms, so it still idles past the timeout before it uses the connection. Reproduced locally with a TCP proxy that adds 40 ms to every chunk: the old test fails with the same error, and the new one passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cwt8ciN4uKrQkEM14TCff2
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
8 of 10 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2193 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 56 56
Lines 5802 5802
Branches 996 988 -8
=========================================
Hits 5802 5802 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A 500 ms budget only made the keep-alive test less likely to fail: a handshake that takes longer still loses the race. Through a proxy that adds 250 ms to every chunk, the 500 ms version fails with "Redis timed out after 500ms". Keyv times the connect with a JS setTimeout, so the test now fakes setTimeout and clearTimeout while it connects. The race can't time out, however long the handshake takes, and the test moves the clock past the timeout instead of sleeping, so it runs in about 50 ms instead of 600 ms. node-redis's TCP connectTimeout runs on Node's internal timers, which stay real, so connectionTimeout is now 1 s, the window the other tests that use the server's clock got in #2182. The test also checks that the same client is still open after the timeout. Before, a client torn down when the timeout elapsed went unnoticed, because the adapter reconnects on the next call. A timer that destroys the client after the timeout now fails the test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cwt8ciN4uKrQkEM14TCff2
jaredwray
pushed a commit
that referenced
this pull request
Oct 4, 2026
Brings in #2193, which this branch already carried as d16fffe and 538c8d0, so the release diff is the version bump and docs again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cwt8ciN4uKrQkEM14TCff2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce?
Test fix (flaky test). No source changes.
Problem
getClient > should keep a successful connection alive after connectionTimeout elapsesconnected to a real Redis withconnectionTimeout: 50. The TCP connect and the handshake therefore had to beat a 50 ms timer. When every package's tests run in parallel in CI, they sometimes don't:It has failed this way twice today: in the
codecovjob onmainat 6d4b270, and on the release PR #2192. The release workflow'stestjob runs the same suite, so this test can also block a release.Fix
A bigger budget only makes a failure less likely. The first commit used 500 ms, and through a proxy that adds 250 ms to every chunk it still fails with
Redis timed out after 500ms. Following #2182, the test now controls the clock it was racing instead of racing it:setTimeout(raceWithTimeout). The test fakessetTimeoutandclearTimeoutwhile it connects, so the race can't time out however long the handshake takes.connectTimeoutruns on Node's internal timers, which stay real.connectionTimeoutis therefore 1 s, the window mono - test: Stop expiry tests from racing a 100 ms TTL #2182 gave the tests that use the server's clock. It only bounds the TCP connect, not the handshake.setTimeoutfor its ping timer, which is off unlesspingIntervalis set. Real timers come back beforeset/get, and afinallyrestores them and disconnects even if an assertion fails.The test also checks that the same client is still open after the timeout. Before, a client torn down at the timeout went unnoticed, because the adapter reconnects on the next call. No retries were added (see AGENTS.md).
Verification
timed out after 50ms, the CI error)timed out after 500ms)client.isOpenis false)get-client.test.tsfile passes (35/35).biome check --error-on-warningsis clean.tscon the test file shows no new errors (0 before, 0 after).🤖 Generated with Claude Code
https://claude.ai/code/session_01Cwt8ciN4uKrQkEM14TCff2