Skip to content

test(e2e): unix domain socket (uds/ipc)#1208

Merged
chimurai merged 1 commit intomasterfrom
test-unix-domain-socket
Apr 19, 2026
Merged

test(e2e): unix domain socket (uds/ipc)#1208
chimurai merged 1 commit intomasterfrom
test-unix-domain-socket

Conversation

@chimurai
Copy link
Copy Markdown
Owner

@chimurai chimurai commented Apr 19, 2026

add e2e test for unix domain socket

related: #434

Summary by CodeRabbit

  • Tests
    • Added an end-to-end test validating HTTP proxying to an upstream server over a Unix Domain Socket.
    • Confirms a proxied GET returns HTTP 200 with the expected JSON response and ensures proper startup, teardown and resource cleanup of test servers.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 67d3f456-2969-4c1c-8452-a347e81767d7

📥 Commits

Reviewing files that changed from the base of the PR and between 36c0944 and c4f50e0.

📒 Files selected for processing (1)
  • test/e2e/unix-domain-socket.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/e2e/unix-domain-socket.spec.ts

📝 Walkthrough

Walkthrough

Adds a Vitest end-to-end test that starts an Express target server listening on a Unix Domain Socket and a proxy Express server that forwards to that socket, then issues an HTTP GET to the proxy at /hello and asserts a 200 JSON response { ok: true }.

Changes

Cohort / File(s) Summary
Unix Domain Socket E2E Test
test/e2e/unix-domain-socket.spec.ts
Adds a new Vitest E2E suite. Introduces startTargetServer(socketPath) (Express listening on a .sock path) and startProxyServer(socketPath) (proxy middleware targeting socketPath, listening on an ephemeral TCP port). Test uses randomUUID() for socket path, await using / Symbol.asyncDispose for cleanup, queries proxy with Supertest, and asserts 200 with JSON { ok: true }.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I found a socket in the ground,

A tiny pipe with whispers round.
Proxy hopped, the target sang,
/hello echoed—my heart went bang! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding an E2E test for Unix Domain Socket (UDS/IPC) functionality, which matches the single new test file added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test-unix-domain-socket

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 19, 2026

npm i https://pkg.pr.new/http-proxy-middleware@1208

commit: c4f50e0

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 19, 2026

Coverage Status

coverage: 93.956%. remained the same — test-unix-domain-socket into master

@chimurai chimurai force-pushed the test-unix-domain-socket branch from 87ec318 to 36c0944 Compare April 19, 2026 17:34
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/e2e/unix-domain-socket.spec.ts`:
- Around line 57-62: The test is using proxyServer.server.address()
(AddressInfo) to build a URL which can return wildcard bind addresses like '::'
or '0.0.0.0'; instead pass the actual Node http.Server instance directly into
Supertest's request() so it handles binding and ports for you. Replace the usage
of address/AddressInfo and change the call from
request(`http://[${address.address}]:${address.port}`) to
request(proxyServer.server) and then call .get('/hello').expect(200); this
removes the brittle address lookup and uses proxyServer.server as the target for
Supertest.
- Around line 19-24: The helper functions startTargetServer and startProxyServer
call server.listen(...) but return immediately, causing a race where
server.address() may be called before binding completes; change both helpers to
await the 'listening' event (e.g. using events.once(server, 'listening')) after
calling listen(…) so they only return once bound, and update the async disposal
close logic (targetServer.close and proxyServer.close) to propagate errors by
rejecting the Promise if the close callback receives an error instead of always
resolving.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 27bd4c69-d24c-443e-a168-4d613ab11e14

📥 Commits

Reviewing files that changed from the base of the PR and between 4be9fbd and 87ec318.

📒 Files selected for processing (1)
  • test/e2e/unix-domain-socket.spec.ts

Comment thread test/e2e/unix-domain-socket.spec.ts Outdated
Comment thread test/e2e/unix-domain-socket.spec.ts Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (2)
test/e2e/unix-domain-socket.spec.ts (2)

59-64: ⚠️ Potential issue | 🟡 Minor

Pass the server directly to Supertest.

server.address().address can be a wildcard bind address like :: or 0.0.0.0, and the bracketed URL assumes IPv6 formatting. Supertest can target the server instance directly, avoiding this brittle address lookup. This was previously flagged and still applies.

Proposed fix
-import type { AddressInfo } from 'node:net';
@@
-    const address = proxyServer.server.address() as AddressInfo;
-
     // ACT
-    const response = await request(`http://[${address.address}]:${address.port}`)
+    const response = await request(proxyServer.server)
       .get('/hello')
       .expect(200);

Verification:

Does Supertest's request() function accept a Node.js http.Server instance directly?
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/e2e/unix-domain-socket.spec.ts` around lines 59 - 64, The test is
brittle because it constructs a bracketed URL from proxyServer.server.address()
(variable address) which can be a wildcard like :: or 0.0.0.0; instead pass the
server instance directly to Supertest. Replace the use of address/address.port
and the template URL in the request(...) call with request(proxyServer.server)
(keeping the subsequent .get('/hello').expect(200)), and remove the earlier
const address = proxyServer.server.address() as AddressInfo since it's no longer
needed.

21-27: ⚠️ Potential issue | 🟠 Major

Wait for both servers to bind and propagate close errors.

listen() returns before the server is guaranteed to be bound, so the test can race with startup. The close callbacks also always resolve, hiding teardown errors. This remains the same lifecycle issue previously flagged.

Proposed fix
+import { once } from 'node:events';
 import { randomUUID } from 'node:crypto';
 import type { AddressInfo } from 'node:net';
 import { tmpdir } from 'node:os';
 import { join } from 'node:path';
@@
-    const targetServer = app.listen(socketPath);
+    const targetServer = app.listen(socketPath);
+    await once(targetServer, 'listening');
@@
-        await new Promise<void>((resolve, reject) => {
-          targetServer.close(() => resolve());
+        await new Promise<void>((resolve, reject) => {
+          targetServer.close((error) => (error ? reject(error) : resolve()));
         });
@@
-    const proxyServer = createApp(proxyMiddleware).listen(0);
+    const proxyServer = createApp(proxyMiddleware).listen(0);
+    await once(proxyServer, 'listening');
@@
-        await new Promise<void>((resolve, reject) => {
-          proxyServer.close(() => resolve());
+        await new Promise<void>((resolve, reject) => {
+          proxyServer.close((error) => (error ? reject(error) : resolve()));
         });

Verification:

#!/bin/bash
# Confirm both listen() calls are followed by readiness waits and close callbacks propagate errors.
rg -n -C3 'listen\(|Symbol\.asyncDispose|close\(' test/e2e/unix-domain-socket.spec.ts

Also applies to: 39-46

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/e2e/unix-domain-socket.spec.ts` around lines 21 - 27, The test races on
startup and hides teardown errors: ensure both app.listen(...) calls wait for
the server to be actually bound (use the listen callback or await the
'listening' event for the server returned as targetServer and the other server)
before proceeding, and update the Symbol.asyncDispose close logic so the close
callback rejects on error (propagate any error passed into the close callback
instead of always resolving) so teardown failures surface; apply the same
listen/readiness and close-error propagation changes for the other server
instance referenced in this spec.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@test/e2e/unix-domain-socket.spec.ts`:
- Around line 59-64: The test is brittle because it constructs a bracketed URL
from proxyServer.server.address() (variable address) which can be a wildcard
like :: or 0.0.0.0; instead pass the server instance directly to Supertest.
Replace the use of address/address.port and the template URL in the request(...)
call with request(proxyServer.server) (keeping the subsequent
.get('/hello').expect(200)), and remove the earlier const address =
proxyServer.server.address() as AddressInfo since it's no longer needed.
- Around line 21-27: The test races on startup and hides teardown errors: ensure
both app.listen(...) calls wait for the server to be actually bound (use the
listen callback or await the 'listening' event for the server returned as
targetServer and the other server) before proceeding, and update the
Symbol.asyncDispose close logic so the close callback rejects on error
(propagate any error passed into the close callback instead of always resolving)
so teardown failures surface; apply the same listen/readiness and close-error
propagation changes for the other server instance referenced in this spec.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c0316260-5f4e-45e2-be93-713dd7eb0dc7

📥 Commits

Reviewing files that changed from the base of the PR and between 87ec318 and 36c0944.

📒 Files selected for processing (1)
  • test/e2e/unix-domain-socket.spec.ts

@chimurai chimurai force-pushed the test-unix-domain-socket branch from 36c0944 to c4f50e0 Compare April 19, 2026 17:49
@chimurai chimurai merged commit 3184776 into master Apr 19, 2026
21 checks passed
@chimurai chimurai deleted the test-unix-domain-socket branch April 19, 2026 17:57
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.

2 participants