Skip to content

Conversation

@mcollina
Copy link
Member

Summary

  • Updated 13 test files to call server.closeIdleConnections() before closing servers in after() hooks
  • This ensures idle connections are properly drained rather than abruptly terminated
  • Prevents intermittent ECONNRESET errors on macOS

Files updated

  • test/fetch/encoding.js
  • test/fetch/client-node-max-header-size.js
  • test/client-node-max-header-size.js
  • test/client-request.js
  • test/env-http-proxy-agent-nodejs-bundle.js
  • test/issue-4244.js
  • test/max-response-size.js
  • test/mock-agent.js
  • test/mock-client.js
  • test/mock-pool.js
  • test/no-strict-content-length.js
  • test/request.js
  • test/snapshot-testing.js

Test plan

  • Ran encoding tests multiple times locally to verify stability
  • Linting passes

🤖 Generated with Claude Code

@mcollina mcollina force-pushed the fix/flaky-tests-server-cleanup branch 2 times, most recently from a1571a7 to e037410 Compare January 24, 2026 15:55
Updated 13 test files to call server.closeAllConnections?.() before
closing servers in after() hooks. This ensures all connections
(both idle and active) are forcefully closed when the method is
available (http.Server), preventing test timeouts. Uses optional
chaining to safely handle net.Server which lacks this method.

Files updated:
- test/fetch/encoding.js
- test/fetch/client-node-max-header-size.js
- test/client-node-max-header-size.js
- test/client-request.js
- test/env-http-proxy-agent-nodejs-bundle.js
- test/issue-4244.js
- test/max-response-size.js
- test/mock-agent.js
- test/mock-client.js
- test/mock-pool.js
- test/no-strict-content-length.js
- test/request.js
- test/snapshot-testing.js

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina mcollina force-pushed the fix/flaky-tests-server-cleanup branch from e037410 to d4a9277 Compare January 24, 2026 15:56
Replace async after() hooks with synchronous ones to avoid
"Promise resolution is still pending but the event loop has
already resolved" errors.

The pattern `server.closeAllConnections?.()` followed by
`server.close()` properly handles connection cleanup without
needing to await.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Copy link
Member

@ronag ronag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.26%. Comparing base (4920fc4) to head (bd241d9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4764   +/-   ##
=======================================
  Coverage   93.26%   93.26%           
=======================================
  Files         109      109           
  Lines       34029    34029           
=======================================
  Hits        31738    31738           
  Misses       2291     2291           

☔ 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.

4 participants