mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-30 07:14:39 +08:00
test: make child backpressure event ordering deterministic
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user