From 4d8ee64bb5c1b522fd2b513e509fee01618c6bd2 Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Sat, 20 Feb 2021 03:50:18 +0000 Subject: [PATCH 1/4] fix(runtime/testing): false positive for timers when an error is thrown --- cli/tests/integration_tests.rs | 6 ++++++ cli/tests/test_finally_cleartimeout.out | 22 ++++++++++++++++++++++ cli/tests/test_finally_cleartimeout.ts | 8 ++++++++ runtime/js/40_testing.js | 13 ++++++++----- 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 cli/tests/test_finally_cleartimeout.out create mode 100644 cli/tests/test_finally_cleartimeout.ts diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index a25a51b2003fb8..6ba6359fdc0720 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -2354,6 +2354,12 @@ mod integration { output: "deno_test.out", }); + itest!(deno_test_finally_cleartimeout { + args: "test test_finally_cleartimeout.ts", + exit_code: 1, + output: "test_finally_cleartimeout.out", + }); + itest!(deno_test_unresolved_promise { args: "test test_unresolved_promise.js", exit_code: 1, diff --git a/cli/tests/test_finally_cleartimeout.out b/cli/tests/test_finally_cleartimeout.out new file mode 100644 index 00000000000000..47f8aff54a28cf --- /dev/null +++ b/cli/tests/test_finally_cleartimeout.out @@ -0,0 +1,22 @@ +Check [WILDCARD]/$deno$test.ts +running 1 tests +test test ... FAILED ([WILDCARD]) + +failures: + +test +Error: fail + at [WILDCARD]/test_finally_cleartimeout.ts:4:11 + at asyncOpSanitizer (deno:runtime/js/40_testing.js:38:15) + at Object.resourceSanitizer [as fn] (deno:runtime/js/40_testing.js:74:13) + at TestRunner.[Symbol.asyncIterator] (deno:runtime/js/40_testing.js:249:24) + at AsyncGenerator.next () + at Object.runTests (deno:runtime/js/40_testing.js:326:22) + at async [WILDCARD]/$deno$test.ts:3:1 + +failures: + + test + +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) + diff --git a/cli/tests/test_finally_cleartimeout.ts b/cli/tests/test_finally_cleartimeout.ts new file mode 100644 index 00000000000000..0a9be962891e0b --- /dev/null +++ b/cli/tests/test_finally_cleartimeout.ts @@ -0,0 +1,8 @@ +Deno.test("test", function() { + const timer = setTimeout(() => null, 10000); + try { + throw new Error("fail"); + } finally { + clearTimeout(timer); + } +}); diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js index 15545fc49d350f..2258dc7b636d61 100644 --- a/runtime/js/40_testing.js +++ b/runtime/js/40_testing.js @@ -34,11 +34,14 @@ function assertOps(fn) { return async function asyncOpSanitizer() { const pre = metrics(); - await fn(); - // Defer until next event loop turn - that way timeouts and intervals - // cleared can actually be removed from resource table, otherwise - // false positives may occur (https://github.com/denoland/deno/issues/4591) - await delay(0); + try { + await fn(); + } finally { + // Defer until next event loop turn - that way timeouts and intervals + // cleared can actually be removed from resource table, otherwise + // false positives may occur (https://github.com/denoland/deno/issues/4591) + await delay(0); + } const post = metrics(); // We're checking diff because one might spawn HTTP server in the background // that will be a pending async op before test starts. From db9fab44a6a9c62a1ba9700e3d026fb8ac7c8ddf Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Sat, 20 Feb 2021 04:00:13 +0000 Subject: [PATCH 2/4] Format --- cli/tests/test_finally_cleartimeout.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/tests/test_finally_cleartimeout.ts b/cli/tests/test_finally_cleartimeout.ts index 0a9be962891e0b..f50f0e5a3ffa55 100644 --- a/cli/tests/test_finally_cleartimeout.ts +++ b/cli/tests/test_finally_cleartimeout.ts @@ -1,4 +1,4 @@ -Deno.test("test", function() { +Deno.test("test", function () { const timer = setTimeout(() => null, 10000); try { throw new Error("fail"); From 59a00dc74ca3fe99f98f828df0ffa998a2c7b7fe Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Sun, 21 Feb 2021 08:58:05 +0000 Subject: [PATCH 3/4] Bump CI From dd764d31ed1403fad94fa32024ada335b87fddd4 Mon Sep 17 00:00:00 2001 From: Casper Beyer Date: Sun, 21 Feb 2021 15:40:58 +0000 Subject: [PATCH 4/4] Fixup test --- cli/tests/test_finally_cleartimeout.out | 11 ++++++----- cli/tests/test_finally_cleartimeout.ts | 5 ++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cli/tests/test_finally_cleartimeout.out b/cli/tests/test_finally_cleartimeout.out index 47f8aff54a28cf..c8f412bf0f37fd 100644 --- a/cli/tests/test_finally_cleartimeout.out +++ b/cli/tests/test_finally_cleartimeout.out @@ -1,10 +1,11 @@ Check [WILDCARD]/$deno$test.ts -running 1 tests -test test ... FAILED ([WILDCARD]) +running 2 tests +test error ... FAILED ([WILDCARD]) +test success ... ok ([WILDCARD]) failures: -test +error Error: fail at [WILDCARD]/test_finally_cleartimeout.ts:4:11 at asyncOpSanitizer (deno:runtime/js/40_testing.js:38:15) @@ -16,7 +17,7 @@ Error: fail failures: - test + error -test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) +test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD]) diff --git a/cli/tests/test_finally_cleartimeout.ts b/cli/tests/test_finally_cleartimeout.ts index f50f0e5a3ffa55..dcc0a4d6411c77 100644 --- a/cli/tests/test_finally_cleartimeout.ts +++ b/cli/tests/test_finally_cleartimeout.ts @@ -1,4 +1,4 @@ -Deno.test("test", function () { +Deno.test("error", function () { const timer = setTimeout(() => null, 10000); try { throw new Error("fail"); @@ -6,3 +6,6 @@ Deno.test("test", function () { clearTimeout(timer); } }); + +Deno.test("success", function () { +});