diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2023-03-25 19:32:11 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-25 21:32:11 +0200 |
commit | 8a4865c3790a6eb93d95189e129b3ee98f349b45 (patch) | |
tree | eb7a7f7a32addcfb49e5814d509c244532e38c2f /cli/tests/unit_node/process_test.ts | |
parent | fe88b53e50034e185246e03be586c470ca4fbf78 (diff) |
feat(test): print pending tests on sigint (#18246)
Diffstat (limited to 'cli/tests/unit_node/process_test.ts')
-rw-r--r-- | cli/tests/unit_node/process_test.ts | 84 |
1 files changed, 50 insertions, 34 deletions
diff --git a/cli/tests/unit_node/process_test.ts b/cli/tests/unit_node/process_test.ts index 7310e4ad7..686a3dbbc 100644 --- a/cli/tests/unit_node/process_test.ts +++ b/cli/tests/unit_node/process_test.ts @@ -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"); }, }); |