From 979d71c883ee76c5e1246c5ad02f2791b745bef6 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Wed, 13 Jan 2021 20:52:12 -0800 Subject: 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. --- cli/tests/unit/process_test.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'cli/tests') 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(); -- cgit v1.2.3