diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-06-10 16:10:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-10 11:10:08 -0400 |
commit | 8f050355ff08e6e44681b20b17885a01e8480b73 (patch) | |
tree | d2f23109b63263408e8278a91386d227d9550679 | |
parent | 4b7d3b060e88c02bc0ca12664f52111a4666b167 (diff) |
fix(cli/js/process): Always return a code in ProcessStatus (#5244)
-rw-r--r-- | cli/js/process.ts | 23 | ||||
-rw-r--r-- | cli/tests/unit/process_test.ts | 16 |
2 files changed, 25 insertions, 14 deletions
diff --git a/cli/js/process.ts b/cli/js/process.ts index cfae7fe56..f318b0c1c 100644 --- a/cli/js/process.ts +++ b/cli/js/process.ts @@ -21,10 +21,11 @@ async function runStatus(rid: number): Promise<ProcessStatus> { if (res.gotSignal) { const signal = res.exitSignal; - return { signal, success: false }; + return { success: false, code: 128 + signal, signal }; + } else if (res.exitCode != 0) { + return { success: false, code: res.exitCode }; } else { - const code = res.exitCode; - return { code, success: code === 0 }; + return { success: true, code: 0 }; } } @@ -92,11 +93,17 @@ export class Process<T extends RunOptions = RunOptions> { } } -export interface ProcessStatus { - success: boolean; - code?: number; - signal?: number; // TODO: Make this a string, e.g. 'SIGTERM'. -} +export type ProcessStatus = + | { + success: true; + code: 0; + signal?: undefined; + } + | { + success: false; + code: number; + signal?: number; + }; function isRid(arg: unknown): arg is number { return !isNaN(arg as number); diff --git a/cli/tests/unit/process_test.ts b/cli/tests/unit/process_test.ts index 79e36dc4b..c6503b2e0 100644 --- a/cli/tests/unit/process_test.ts +++ b/cli/tests/unit/process_test.ts @@ -66,7 +66,7 @@ unitTest( }); const status = await p.status(); assertEquals(status.success, false); - assertEquals(status.code, undefined); + assertEquals(status.code, 128 + 9); assertEquals(status.signal, 9); p.close(); } @@ -358,11 +358,15 @@ unitTest({ perms: { run: true } }, async function killSuccess(): Promise<void> { const status = await p.status(); assertEquals(status.success, false); - // TODO(ry) On Linux, status.code is sometimes undefined and sometimes 1. - // The following assert is causing this test to be flaky. Investigate and - // re-enable when it can be made deterministic. - // assertEquals(status.code, 1); - // assertEquals(status.signal, Deno.Signal.SIGINT); + try { + assertEquals(status.code, 128 + Deno.Signal.SIGINT); + assertEquals(status.signal, Deno.Signal.SIGINT); + } catch { + // TODO(nayeemrmn): On Windows sometimes the following values are given + // instead. Investigate and remove this catch when fixed. + assertEquals(status.code, 1); + assertEquals(status.signal, undefined); + } p.close(); }); |