Skip to content

fix: register connect listener before initiating requests in close-and-destroy test#5272

Open
mcollina wants to merge 1 commit intomainfrom
fix-5265-close-and-destroy
Open

fix: register connect listener before initiating requests in close-and-destroy test#5272
mcollina wants to merge 1 commit intomainfrom
fix-5265-close-and-destroy

Conversation

@mcollina
Copy link
Copy Markdown
Member

@mcollina mcollina commented May 8, 2026

Fixes #5265

Problem

The test/close-and-destroy.js test 'close should still reconnect' was flaky on Windows. It registered the client.once('connect', ...) listener after calling makeRequest(), which initiates the connection. On fast connections (like localhost on Windows), the connection could complete before the listener was registered, causing the client[kSocket].destroy() to never execute and making the test outcome non-deterministic.

Fix

Move the client.once('connect', ...) registration to before makeRequest() so the listener is always in place when the connection is established.

The test intent is to destroy the socket on connect so the client must reconnect and complete pending requests. This only works if the listener is registered before the connect event fires.

…d-destroy test

The 'close should still reconnect' test registered the 'connect'
listener after makeRequest() was called. On fast connections
(like localhost on Windows), the connection could complete before
the listener was registered, causing the socket to never be
destroyed and making the test flaky.

Move the client.once('connect', ...) registration before
makeRequest() to ensure the listener is always in place when
the connection is established.
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.27%. Comparing base (397bc13) to head (b435f03).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5272   +/-   ##
=======================================
  Coverage   93.27%   93.27%           
=======================================
  Files         110      110           
  Lines       36380    36380           
=======================================
+ Hits        33934    33935    +1     
+ Misses       2446     2445    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flaky] test\close-and-destroy.js

2 participants