diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2019-04-21 18:26:56 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-04-21 21:26:56 -0400 |
commit | 1d4b92ac85d8c850270ca859f928404c72c0a49a (patch) | |
tree | 2f45ea65a3a3c5879fe7b16cacfd5624d86764cd /js/process_test.ts | |
parent | 9dfebbc9496138efbeedc431068f41662c780f3e (diff) |
Add Deno.kill(pid, signo) and process.kill(signo) (Unix only) (#2177)
Diffstat (limited to 'js/process_test.ts')
-rw-r--r-- | js/process_test.ts | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/js/process_test.ts b/js/process_test.ts index c89e1cae7..8d266617a 100644 --- a/js/process_test.ts +++ b/js/process_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import { test, testPerm, assert, assertEquals } from "./test_util.ts"; -const { run, DenoError, ErrorKind } = Deno; +const { kill, run, DenoError, ErrorKind } = Deno; test(function runPermissions(): void { let caughtError = false; @@ -223,3 +223,69 @@ testPerm({ run: true }, async function runEnv(): Promise<void> { assertEquals(s, "01234567"); p.close(); }); + +testPerm({ run: true }, async function runClose(): Promise<void> { + const p = run({ + args: [ + "python", + "-c", + "from time import sleep; import sys; sleep(10000); sys.stderr.write('error')" + ], + stderr: "piped" + }); + assert(!p.stdin); + assert(!p.stdout); + + p.close(); + + const data = new Uint8Array(10); + let r = await p.stderr.read(data); + assertEquals(r.nread, 0); + assertEquals(r.eof, true); +}); + +test(function signalNumbers(): void { + if (Deno.platform.os === "mac") { + assertEquals(Deno.Signal.SIGSTOP, 17); + } else if (Deno.platform.os === "linux") { + assertEquals(Deno.Signal.SIGSTOP, 19); + } +}); + +// Ignore signal tests on windows for now... +if (Deno.platform.os !== "win") { + testPerm({ run: true }, async function killSuccess(): Promise<void> { + const p = run({ + args: ["python", "-c", "from time import sleep; sleep(10000)"] + }); + + assertEquals(Deno.Signal.SIGINT, 2); + kill(p.pid, Deno.Signal.SIGINT); + const status = await p.status(); + + assertEquals(status.success, false); + assertEquals(status.code, undefined); + assertEquals(status.signal, Deno.Signal.SIGINT); + }); + + testPerm({ run: true }, async function killFailed(): Promise<void> { + const p = run({ + args: ["python", "-c", "from time import sleep; sleep(10000)"] + }); + assert(!p.stdin); + assert(!p.stdout); + + let err; + try { + kill(p.pid, 12345); + } catch (e) { + err = e; + } + + assert(!!err); + assertEquals(err.kind, Deno.ErrorKind.InvalidInput); + assertEquals(err.name, "InvalidInput"); + + p.close(); + }); +} |