From b198bfd7950ce3f20aeaef265be59ff038fc4e11 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sat, 12 Mar 2022 01:18:49 +0900 Subject: refactor(core): validate promise id in refOp (#13905) --- cli/tests/unit/ref_unref_test.ts | 10 ++++++++++ cli/tests/unit/test_util.ts | 18 ++++++++++++++++++ cli/tests/unit/timers_test.ts | 18 +----------------- 3 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 cli/tests/unit/ref_unref_test.ts (limited to 'cli/tests/unit') diff --git a/cli/tests/unit/ref_unref_test.ts b/cli/tests/unit/ref_unref_test.ts new file mode 100644 index 000000000..da6e95efc --- /dev/null +++ b/cli/tests/unit/ref_unref_test.ts @@ -0,0 +1,10 @@ +import { assertNotEquals, execCode } from "./test_util.ts"; + +Deno.test("[unrefOp] unref'ing invalid ops does not have effects", async () => { + const [statusCode, _] = await execCode(` + Deno.core.unrefOp(-1); + setTimeout(() => { throw new Error() }, 10) + `); + // Invalid unrefOp call doesn't affect exit condition of event loop + assertNotEquals(statusCode, 0); +}); diff --git a/cli/tests/unit/test_util.ts b/cli/tests/unit/test_util.ts index 3591864d4..b18ad9550 100644 --- a/cli/tests/unit/test_util.ts +++ b/cli/tests/unit/test_util.ts @@ -27,3 +27,21 @@ export function pathToAbsoluteFileUrl(path: string): URL { return new URL(`file://${Deno.build.os === "windows" ? "/" : ""}${path}`); } + +const decoder = new TextDecoder(); + +export async function execCode(code: string) { + const p = Deno.run({ + cmd: [ + Deno.execPath(), + "eval", + "--unstable", + "--no-check", + code, + ], + stdout: "piped", + }); + const [status, output] = await Promise.all([p.status(), p.output()]); + p.close(); + return [status.code, decoder.decode(output)]; +} diff --git a/cli/tests/unit/timers_test.ts b/cli/tests/unit/timers_test.ts index e85a2effc..ac0403bf7 100644 --- a/cli/tests/unit/timers_test.ts +++ b/cli/tests/unit/timers_test.ts @@ -6,11 +6,10 @@ import { Deferred, deferred, delay, + execCode, unreachable, } from "./test_util.ts"; -const decoder = new TextDecoder(); - Deno.test(async function functionParameterBindingSuccess() { const promise = deferred(); let count = 0; @@ -578,21 +577,6 @@ Deno.test( }, ); -async function execCode(code: string) { - const p = Deno.run({ - cmd: [ - Deno.execPath(), - "eval", - "--unstable", - code, - ], - stdout: "piped", - }); - const [status, output] = await Promise.all([p.status(), p.output()]); - p.close(); - return [status.code, decoder.decode(output)]; -} - Deno.test({ name: "unrefTimer", permissions: { run: true }, -- cgit v1.2.3