mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
chore(ext/node): make process_test more reliable (#22703)
This commit is contained in:
parent
c99a0492b7
commit
10557ff15c
1 changed files with 78 additions and 50 deletions
|
@ -19,6 +19,7 @@ import {
|
|||
assertObjectMatch,
|
||||
assertStrictEquals,
|
||||
assertThrows,
|
||||
fail,
|
||||
} from "@std/assert/mod.ts";
|
||||
import { stripColor } from "@std/fmt/colors.ts";
|
||||
import * as path from "@std/path/mod.ts";
|
||||
|
@ -184,12 +185,15 @@ Deno.test({
|
|||
name: "process.on signal",
|
||||
ignore: Deno.build.os == "windows",
|
||||
async fn() {
|
||||
const testTimeout = setTimeout(() => fail("Test timed out"), 10_000);
|
||||
try {
|
||||
const process = new Deno.Command(Deno.execPath(), {
|
||||
args: [
|
||||
"eval",
|
||||
`
|
||||
import process from "node:process";
|
||||
setInterval(() => {}, 1000);
|
||||
console.log("ready");
|
||||
process.on("SIGINT", () => {
|
||||
console.log("foo");
|
||||
});
|
||||
|
@ -198,15 +202,29 @@ Deno.test({
|
|||
stdout: "piped",
|
||||
stderr: "null",
|
||||
}).spawn();
|
||||
await delay(500);
|
||||
let output = "";
|
||||
process.stdout.pipeThrough(new TextDecoderStream()).pipeTo(
|
||||
new WritableStream({
|
||||
write(chunk) {
|
||||
output += chunk;
|
||||
},
|
||||
}),
|
||||
);
|
||||
while (!output.includes("ready\n")) {
|
||||
await delay(10);
|
||||
}
|
||||
output = "";
|
||||
for (const _ of Array(3)) {
|
||||
process.kill("SIGINT");
|
||||
await delay(20);
|
||||
while (!output.includes("foo\n")) {
|
||||
await delay(10);
|
||||
}
|
||||
}
|
||||
await delay(20);
|
||||
process.kill("SIGTERM");
|
||||
const output = await process.output();
|
||||
assertEquals(new TextDecoder().decode(output.stdout), "foo\nfoo\nfoo\n");
|
||||
await process.status;
|
||||
} finally {
|
||||
clearTimeout(testTimeout);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -214,11 +232,14 @@ Deno.test({
|
|||
name: "process.off signal",
|
||||
ignore: Deno.build.os == "windows",
|
||||
async fn() {
|
||||
const testTimeout = setTimeout(() => fail("Test timed out"), 10_000);
|
||||
try {
|
||||
const process = new Deno.Command(Deno.execPath(), {
|
||||
args: [
|
||||
"eval",
|
||||
`
|
||||
import process from "node:process";
|
||||
console.log("ready");
|
||||
setInterval(() => {}, 1000);
|
||||
const listener = () => {
|
||||
console.log("foo");
|
||||
|
@ -230,19 +251,26 @@ Deno.test({
|
|||
stdout: "piped",
|
||||
stderr: "null",
|
||||
}).spawn();
|
||||
await delay(500);
|
||||
for (const _ of Array(3)) {
|
||||
try {
|
||||
process.kill("SIGINT");
|
||||
} catch { /* should die after the first one */ }
|
||||
await delay(20);
|
||||
let output = "";
|
||||
process.stdout.pipeThrough(new TextDecoderStream()).pipeTo(
|
||||
new WritableStream({
|
||||
write(chunk) {
|
||||
output += chunk;
|
||||
},
|
||||
}),
|
||||
);
|
||||
while (!output.includes("ready\n")) {
|
||||
await delay(10);
|
||||
}
|
||||
output = "";
|
||||
process.kill("SIGINT");
|
||||
while (!output.includes("foo\n")) {
|
||||
await delay(10);
|
||||
}
|
||||
await process.status;
|
||||
} finally {
|
||||
clearTimeout(testTimeout);
|
||||
}
|
||||
await delay(20);
|
||||
try {
|
||||
process.kill("SIGTERM");
|
||||
} catch { /* should be dead, avoid hanging just in case */ }
|
||||
const output = await process.output();
|
||||
assertEquals(new TextDecoder().decode(output.stdout), "foo\n");
|
||||
},
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue