mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
feat(runtime/signal): implement SIGINT and SIGBREAK for windows (#14694)
This commit adds support for SIGINT and SIGBREAK signals on Windows platform. Co-authored-by: orange soeur <juzi201314@gmail.com>
This commit is contained in:
parent
21dfeea3c4
commit
24571a3952
4 changed files with 242 additions and 89 deletions
|
@ -4,89 +4,102 @@ import { assertEquals, assertThrows, deferred, delay } from "./test_util.ts";
|
|||
Deno.test(
|
||||
{ ignore: Deno.build.os !== "windows" },
|
||||
function signalsNotImplemented() {
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.addSignalListener("SIGINT", () => {});
|
||||
},
|
||||
Error,
|
||||
"not implemented",
|
||||
);
|
||||
const msg =
|
||||
"Windows only supports ctrl-c (SIGINT) and ctrl-break (SIGBREAK).";
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.addSignalListener("SIGALRM", () => {});
|
||||
},
|
||||
Error,
|
||||
"not implemented",
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.addSignalListener("SIGCHLD", () => {});
|
||||
},
|
||||
Error,
|
||||
"not implemented",
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.addSignalListener("SIGHUP", () => {});
|
||||
},
|
||||
Error,
|
||||
"not implemented",
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.addSignalListener("SIGINT", () => {});
|
||||
},
|
||||
Error,
|
||||
"not implemented",
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.addSignalListener("SIGIO", () => {});
|
||||
},
|
||||
Error,
|
||||
"not implemented",
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.addSignalListener("SIGPIPE", () => {});
|
||||
},
|
||||
Error,
|
||||
"not implemented",
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.addSignalListener("SIGQUIT", () => {});
|
||||
},
|
||||
Error,
|
||||
"not implemented",
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.addSignalListener("SIGTERM", () => {});
|
||||
},
|
||||
Error,
|
||||
"not implemented",
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.addSignalListener("SIGUSR1", () => {});
|
||||
},
|
||||
Error,
|
||||
"not implemented",
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.addSignalListener("SIGUSR2", () => {});
|
||||
},
|
||||
Error,
|
||||
"not implemented",
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.addSignalListener("SIGWINCH", () => {});
|
||||
},
|
||||
Error,
|
||||
"not implemented",
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => Deno.addSignalListener("SIGKILL", () => {}),
|
||||
Error,
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => Deno.addSignalListener("SIGSTOP", () => {}),
|
||||
Error,
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => Deno.addSignalListener("SIGILL", () => {}),
|
||||
Error,
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => Deno.addSignalListener("SIGFPE", () => {}),
|
||||
Error,
|
||||
msg,
|
||||
);
|
||||
assertThrows(
|
||||
() => Deno.addSignalListener("SIGSEGV", () => {}),
|
||||
Error,
|
||||
msg,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
@ -169,7 +182,6 @@ Deno.test(
|
|||
// This tests that pending op_signal_poll doesn't block the runtime from exiting the process.
|
||||
Deno.test(
|
||||
{
|
||||
ignore: Deno.build.os === "windows",
|
||||
permissions: { run: true, read: true },
|
||||
},
|
||||
async function canExitWhileListeningToSignal() {
|
||||
|
@ -177,7 +189,7 @@ Deno.test(
|
|||
args: [
|
||||
"eval",
|
||||
"--unstable",
|
||||
"Deno.addSignalListener('SIGIO', () => {})",
|
||||
"Deno.addSignalListener('SIGINT', () => {})",
|
||||
],
|
||||
});
|
||||
assertEquals(status.code, 0);
|
||||
|
@ -186,21 +198,58 @@ Deno.test(
|
|||
|
||||
Deno.test(
|
||||
{
|
||||
ignore: Deno.build.os === "windows",
|
||||
ignore: Deno.build.os !== "windows",
|
||||
permissions: { run: true },
|
||||
},
|
||||
function signalInvalidHandlerTest() {
|
||||
assertThrows(() => {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
Deno.addSignalListener("SIGINT", "handler" as any);
|
||||
});
|
||||
assertThrows(() => {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
Deno.removeSignalListener("SIGINT", "handler" as any);
|
||||
});
|
||||
function windowsThrowsOnNegativeProcessIdTest() {
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.kill(-1, "SIGINT");
|
||||
},
|
||||
TypeError,
|
||||
"Invalid process id (pid) -1 for signal SIGINT.",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
{
|
||||
ignore: Deno.build.os !== "windows",
|
||||
permissions: { run: true },
|
||||
},
|
||||
function noOpenSystemIdleProcessTest() {
|
||||
let signal: Deno.Signal = "SIGKILL";
|
||||
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.kill(0, signal);
|
||||
},
|
||||
TypeError,
|
||||
`Cannot use ${signal} on PID 0`,
|
||||
);
|
||||
|
||||
signal = "SIGTERM";
|
||||
assertThrows(
|
||||
() => {
|
||||
Deno.kill(0, signal);
|
||||
},
|
||||
TypeError,
|
||||
`Cannot use ${signal} on PID 0`,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(function signalInvalidHandlerTest() {
|
||||
assertThrows(() => {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
Deno.addSignalListener("SIGINT", "handler" as any);
|
||||
});
|
||||
assertThrows(() => {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
Deno.removeSignalListener("SIGINT", "handler" as any);
|
||||
});
|
||||
});
|
||||
|
||||
Deno.test(
|
||||
{
|
||||
ignore: Deno.build.os === "windows",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue