diff options
author | Bert Belder <bertbelder@gmail.com> | 2021-01-13 20:52:12 -0800 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2021-01-14 10:26:59 -0800 |
commit | 979d71c883ee76c5e1246c5ad02f2791b745bef6 (patch) | |
tree | 97e6212460238ed14fa7cf7504f1c70cd311acbb /cli/tests/unit | |
parent | b358426eeae1118e73a5420fbe1b3becdb5371a1 (diff) |
refactor: make Process#kill() throw sensible errors on Windows (#9111)
Previously, calling `Process#kill()` after the process had exited would
sometimes throw a `TypeError` on Windows. After this patch, it will
throw `NotFound` instead, just like other platforms.
This patch also fixes flakiness of the `runKillAfterStatus` test on
Windows.
Diffstat (limited to 'cli/tests/unit')
-rw-r--r-- | cli/tests/unit/process_test.ts | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/cli/tests/unit/process_test.ts b/cli/tests/unit/process_test.ts index 1eaa3c3b3..9bb4d7fc2 100644 --- a/cli/tests/unit/process_test.ts +++ b/cli/tests/unit/process_test.ts @@ -434,16 +434,20 @@ unitTest( }); await p.status(); - // On Windows the underlying Rust API returns `ERROR_ACCESS_DENIED`, - // which serves kind of as a catch all error code. More specific - // error codes do exist, e.g. `ERROR_WAIT_NO_CHILDREN`; it's unclear - // why they're not returned. - const expectedErrorType = Deno.build.os === "windows" - ? Deno.errors.PermissionDenied - : Deno.errors.NotFound; - assertThrows( - () => p.kill(Deno.Signal.SIGTERM), - expectedErrorType, + let error = null; + try { + p.kill(Deno.Signal.SIGTERM); + } catch (e) { + error = e; + } + + assert( + error instanceof Deno.errors.NotFound || + // On Windows, the underlying Windows API may return + // `ERROR_ACCESS_DENIED` when the process has exited, but hasn't been + // completely cleaned up yet and its `pid` is still valid. + (Deno.build.os === "windows" && + error instanceof Deno.errors.PermissionDenied), ); p.close(); |