From 05ce5d3d274fcf5415c6f9bfdb4ad42e4e2c9449 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Sat, 3 Oct 2026 06:14:36 -0500 Subject: [PATCH] test: make child backpressure event ordering deterministic --- tests/corpus/2894-child-stdin-backpressure.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/corpus/2894-child-stdin-backpressure.ts b/tests/corpus/2894-child-stdin-backpressure.ts index f1ceab21d..c46ea1f28 100644 --- a/tests/corpus/2894-child-stdin-backpressure.ts +++ b/tests/corpus/2894-child-stdin-backpressure.ts @@ -8,8 +8,11 @@ const output = child.stdout; if (input === null || output === null) throw new Error("missing pipe"); let count = ""; +let outputEnded = false; +let exited = false; +let exitCode: number | null = null; output.on("data", (chunk) => { count += chunk.toString(); }); -output.on("end", () => { console.log("count", count.trim()); }); +output.on("end", () => { outputEnded = true; console.log("count", count.trim()); }); input.on("drain", () => { console.log("drain", input.writable); input.end(); @@ -18,4 +21,9 @@ input.on("finish", () => { console.log("finish", input.writable); }); input.on("error", (err) => { console.log("error", err.message); }); console.log("boundary", input.write(Buffer.alloc(64 * 1024 + 1, 66))); console.log("write", input.write(Buffer.alloc(1024 * 1024, 65))); -child.on("exit", (code) => { console.log("exit", code); }); +child.on("exit", (code) => { exited = true; exitCode = code; }); +// Exit and stdout EOF can arrive in either order. Close follows both. +child.on("close", () => { + if (!exited || !outputEnded) throw new Error("close before exit or stdout end"); + console.log("exit", exitCode); +});