diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-03-03 18:22:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-03 18:22:53 +0100 |
commit | ee452ad883c1c711839655a307b39e8eea5bf410 (patch) | |
tree | 2812a5201beb2b52c92d6e3c958f2288b0253b68 /cli/js/signal_test.ts | |
parent | 4dc004f0a24fdc81026ec03326b9943a95f1a31d (diff) |
add assertOps sanitizer in cli/js/ unit tests (#4209)
* add "assertOps" test assertion which makes sure test case
is not "leaking" ops - ie. after test finishes there are no
pending async ops
* apply "assertOps" to all tests in "cli/js/"
* fix numerous tests leaking ops
* document problem with edge case in "clearInterval"
and "clearTimeout" implementation where they
may leak async ops
* move "cli/js/worker_test.ts" to "cli/tests/worker_test.ts" and
run as integration test; workers leak ops because of missing
"terminate" implementation
Diffstat (limited to 'cli/js/signal_test.ts')
-rw-r--r-- | cli/js/signal_test.ts | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/cli/js/signal_test.ts b/cli/js/signal_test.ts index 1c8658477..a0588b987 100644 --- a/cli/js/signal_test.ts +++ b/cli/js/signal_test.ts @@ -4,7 +4,8 @@ import { testPerm, assert, assertEquals, - assertThrows + assertThrows, + createResolvable } from "./test_util.ts"; function defer(n: number): Promise<void> { @@ -101,15 +102,13 @@ if (Deno.build.os === "win") { ); }); } else { - testPerm({ run: true, net: true }, async function signalStreamTest(): Promise< - void - > { + testPerm({ run: true }, async function signalStreamTest(): Promise<void> { + const resolvable = createResolvable(); // This prevents the program from exiting. const t = setInterval(() => {}, 1000); let c = 0; const sig = Deno.signal(Deno.Signal.SIGUSR1); - setTimeout(async () => { await defer(20); for (const _ of Array(3)) { @@ -118,6 +117,7 @@ if (Deno.build.os === "win") { await defer(20); } sig.dispose(); + resolvable.resolve(); }); for await (const _ of sig) { @@ -126,25 +126,32 @@ if (Deno.build.os === "win") { assertEquals(c, 3); - clearTimeout(t); + clearInterval(t); + // Defer for a moment to allow async op from `setInterval` to resolve; + // for more explanation see `FIXME` in `cli/js/timers.ts::setGlobalTimeout` + await defer(20); + await resolvable; }); - testPerm( - { run: true, net: true }, - async function signalPromiseTest(): Promise<void> { - // This prevents the program from exiting. - const t = setInterval(() => {}, 1000); + testPerm({ run: true }, async function signalPromiseTest(): Promise<void> { + const resolvable = createResolvable(); + // This prevents the program from exiting. + const t = setInterval(() => {}, 1000); - const sig = Deno.signal(Deno.Signal.SIGUSR1); - setTimeout(() => { - Deno.kill(Deno.pid, Deno.Signal.SIGUSR1); - }, 20); - await sig; - sig.dispose(); + const sig = Deno.signal(Deno.Signal.SIGUSR1); + setTimeout(() => { + Deno.kill(Deno.pid, Deno.Signal.SIGUSR1); + resolvable.resolve(); + }, 20); + await sig; + sig.dispose(); - clearTimeout(t); - } - ); + clearInterval(t); + // Defer for a moment to allow async op from `setInterval` to resolve; + // for more explanation see `FIXME` in `cli/js/timers.ts::setGlobalTimeout` + await defer(20); + await resolvable; + }); testPerm({ run: true }, async function signalShorthandsTest(): Promise<void> { let s: Deno.SignalStream; |