feat(test): print pending tests on sigint (#18246)

This commit is contained in:
Nayeem Rahman 2023-03-25 19:32:11 +00:00 committed by GitHub
parent fe88b53e50
commit 8a4865c379
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 649 additions and 584 deletions

View file

@ -155,24 +155,29 @@ Deno.test({
name: "process.on signal",
ignore: Deno.build.os == "windows",
async fn() {
const promise = deferred();
let c = 0;
const listener = () => {
c += 1;
};
process.on("SIGINT", listener);
setTimeout(async () => {
// Sends SIGINT 3 times.
for (const _ of Array(3)) {
await delay(20);
Deno.kill(Deno.pid, "SIGINT");
}
const process = new Deno.Command(Deno.execPath(), {
args: [
"eval",
`
import process from "node:process";
setInterval(() => {}, 1000);
process.on("SIGINT", () => {
console.log("foo");
});
`,
],
stdout: "piped",
stderr: "null",
}).spawn();
await delay(500);
for (const _ of Array(3)) {
process.kill("SIGINT");
await delay(20);
Deno.removeSignalListener("SIGINT", listener);
promise.resolve();
});
await promise;
assertEquals(c, 3);
}
await delay(20);
process.kill("SIGTERM");
const output = await process.output();
assertEquals(new TextDecoder().decode(output.stdout), "foo\nfoo\nfoo\n");
},
});
@ -180,24 +185,35 @@ Deno.test({
name: "process.off signal",
ignore: Deno.build.os == "windows",
async fn() {
const promise = deferred();
let c = 0;
const listener = () => {
c += 1;
process.off("SIGINT", listener);
};
process.on("SIGINT", listener);
setTimeout(async () => {
// Sends SIGINT 3 times.
for (const _ of Array(3)) {
await delay(20);
Deno.kill(Deno.pid, "SIGINT");
}
const process = new Deno.Command(Deno.execPath(), {
args: [
"eval",
`
import process from "node:process";
setInterval(() => {}, 1000);
const listener = () => {
console.log("foo");
process.off("SIGINT")
};
process.on("SIGINT", listener);
`,
],
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);
promise.resolve();
});
await promise;
assertEquals(c, 1);
}
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");
},
});