Skip to content

Commit 5f5f407

Browse files
committed
test: make descendant pid files signal readiness
1 parent beebeac commit 5f5f407

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

‎test/scripts/managed-child-process.test.ts‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,12 @@ describe("managed-child-process", () => {
240240
import { spawn } from "node:child_process";
241241
import fs from "node:fs";
242242
243-
const descendant = spawn(process.execPath, [
243+
spawn(process.execPath, [
244244
"-e",
245-
"process.on('SIGTERM', () => {}); setTimeout(() => process.exit(0), 5_000); setInterval(() => {}, 1000);",
245+
"require('node:fs').writeFileSync(process.argv[1], String(process.pid)); process.on('SIGTERM', () => {}); setTimeout(() => process.exit(0), 5_000); setInterval(() => {}, 1000);",
246+
process.argv[3],
246247
], { stdio: "ignore" });
247248
fs.writeFileSync(process.argv[2], String(process.pid));
248-
fs.writeFileSync(process.argv[3], String(descendant.pid));
249249
process.on("SIGTERM", () => {});
250250
setInterval(() => {}, 1_000);
251251
`,
@@ -506,10 +506,12 @@ setInterval(() => {}, 1_000);
506506
"-e",
507507
`
508508
const { spawn } = require("node:child_process");
509-
const fs = require("node:fs");
510-
const child = spawn(process.execPath, ["-e", "setInterval(() => {}, 1000)"], { stdio: "ignore" });
511-
child.unref();
512-
fs.writeFileSync(process.argv[1], String(child.pid));
509+
const child = spawn(process.execPath, [
510+
"-e",
511+
"require('node:fs').writeFileSync(process.argv[1], String(process.pid)); process.send('ready'); process.disconnect(); setInterval(() => {}, 1000)",
512+
process.argv[1],
513+
], { stdio: ["ignore", "ignore", "ignore", "ipc"] });
514+
child.once("message", () => process.exit(0));
513515
`,
514516
descendantPidPath,
515517
],
@@ -545,12 +547,12 @@ fs.writeFileSync(process.argv[1], String(child.pid));
545547
import { spawn } from "node:child_process";
546548
import fs from "node:fs";
547549
548-
const descendant = spawn(process.execPath, [
550+
spawn(process.execPath, [
549551
"-e",
550-
"process.on('SIGTERM', () => {}); setInterval(() => {}, 1000);",
552+
"require('node:fs').writeFileSync(process.argv[1], String(process.pid)); process.on('SIGTERM', () => {}); setInterval(() => {}, 1000);",
553+
process.argv[3],
551554
], { stdio: "ignore" });
552555
fs.writeFileSync(process.argv[2], String(process.pid));
553-
fs.writeFileSync(process.argv[3], String(descendant.pid));
554556
for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"]) {
555557
process.on(signal, () => process.exit(0));
556558
}

0 commit comments

Comments
 (0)