From bfb0ca8ffc3986a79dedfadfd88fac7db8928203 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Thu, 15 Oct 2026 16:42:32 -0500 Subject: [PATCH] Print the net corpus's server and client lines in a fixed order The server's 'connection' and the client's 'connect' race, and macOS runs them in the other order from Linux. 5644 now prints both sides once both have run, and 5645 keeps the server's and the client's events in separate lists printed one after the other. --- tests/corpus/5644-net-socket-addresses.ts | 43 ++++++++++++----------- tests/corpus/5645-net-socket-callbacks.ts | 15 +++++--- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/tests/corpus/5644-net-socket-addresses.ts b/tests/corpus/5644-net-socket-addresses.ts index 0053105cd..fff2f7aee 100644 --- a/tests/corpus/5644-net-socket-addresses.ts +++ b/tests/corpus/5644-net-socket-addresses.ts @@ -4,17 +4,25 @@ // the open halves. import * as net from "node:net"; +// The server's 'connection' and the client's 'connect' race (either can +// run first), so each side records its line and both print once both +// have run. +let serverLine: string | null = null; +let clientLine: string | null = null; +let startClient: (() => void) | null = null; +function bothConnected(): void { + if (serverLine === null || clientLine === null || startClient === null) return; + console.log(serverLine); + console.log(clientLine); + startClient(); +} + const server = net.createServer((sock) => { const port = (server.address() as net.AddressInfo).port; - console.log( - "server side", - sock.remoteAddress, - sock.remoteFamily, - typeof sock.remotePort, - sock.localAddress, - sock.localPort === port, - sock.localFamily, - ); + serverLine = + `server side ${sock.remoteAddress} ${sock.remoteFamily} ${typeof sock.remotePort} ` + + `${sock.localAddress} ${sock.localPort === port} ${sock.localFamily}`; + bothConnected(); sock.on("data", (d: Buffer) => { console.log("server got", d.toString(), sock.bytesRead); sock.end("bye"); @@ -36,18 +44,11 @@ server.listen(0, "127.0.0.1", () => { c.bytesRead, ); c.on("connect", () => { - console.log( - "connected", - c.readyState, - c.connecting, - c.pending, - c.remotePort === port, - c.remoteFamily, - c.localAddress, - typeof c.localPort, - c.localFamily, - ); - c.write("hello"); + clientLine = + `connected ${c.readyState} ${c.connecting} ${c.pending} ${c.remotePort === port} ` + + `${c.remoteFamily} ${c.localAddress} ${typeof c.localPort} ${c.localFamily}`; + startClient = () => c.write("hello"); + bothConnected(); }); c.on("data", (d: Buffer) => console.log("client got", d.toString(), c.bytesRead)); c.on("end", () => console.log("end", c.readyState, c.bytesRead, c.bytesWritten)); diff --git a/tests/corpus/5645-net-socket-callbacks.ts b/tests/corpus/5645-net-socket-callbacks.ts index 9bc670dc5..c80704828 100644 --- a/tests/corpus/5645-net-socket-callbacks.ts +++ b/tests/corpus/5645-net-socket-callbacks.ts @@ -3,18 +3,22 @@ // setKeepAlive's chaining. import * as net from "node:net"; +// Each side keeps its own list: the client's callbacks and the server's +// events can interleave either way, so the lists print one after the +// other at the end. const events: string[] = []; +const serverEvents: string[] = []; let serverSockets = 0; const server = net.createServer((sock) => { sock.setEncoding("utf8"); sock.on("data", (d: string) => { - events.push(`server data ${typeof d} ${d}`); - sock.end("pong", () => events.push("server end callback")); + serverEvents.push(`server data ${typeof d} ${d}`); + sock.end("pong", () => serverEvents.push("server end callback")); }); // the first connection's server side (the timeout connection's close // order against the client's depends on the event loop phase) if (serverSockets++ === 0) { - sock.on("close", (hadError: boolean) => events.push(`server close ${hadError}`)); + sock.on("close", (hadError: boolean) => serverEvents.push(`server close ${hadError}`)); } }); @@ -59,7 +63,10 @@ server.listen(0, "127.0.0.1", () => { t.on("timeout", () => events.push("timeout event")); t.on("close", (hadError: boolean) => { events.push(`t close ${hadError}`); - server.close(() => console.log(events.join("\n"))); + server.close(() => { + console.log(serverEvents.join("\n")); + console.log(events.join("\n")); + }); }); }); });