summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/test_tests.rs6
-rw-r--r--cli/tests/testdata/test/ops_sanitizer_multiple_timeout_tests.out57
-rw-r--r--cli/tests/testdata/test/ops_sanitizer_multiple_timeout_tests.ts10
-rw-r--r--cli/tests/testdata/test/ops_sanitizer_unstable.out10
-rw-r--r--cli/tests/testdata/worker_drop_handle_race.js.out2
-rw-r--r--cli/tests/unit/timers_test.ts84
6 files changed, 163 insertions, 6 deletions
diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs
index bddb0cc6e..effd615f6 100644
--- a/cli/tests/integration/test_tests.rs
+++ b/cli/tests/integration/test_tests.rs
@@ -156,6 +156,12 @@ itest!(ops_sanitizer_timeout_failure {
output: "test/ops_sanitizer_timeout_failure.out",
});
+itest!(ops_sanitizer_multiple_timeout_tests {
+ args: "test test/ops_sanitizer_multiple_timeout_tests.ts",
+ exit_code: 1,
+ output: "test/ops_sanitizer_multiple_timeout_tests.out",
+});
+
itest!(ops_sanitizer_nexttick {
args: "test test/ops_sanitizer_nexttick.ts",
output: "test/ops_sanitizer_nexttick.out",
diff --git a/cli/tests/testdata/test/ops_sanitizer_multiple_timeout_tests.out b/cli/tests/testdata/test/ops_sanitizer_multiple_timeout_tests.out
new file mode 100644
index 000000000..1981a2500
--- /dev/null
+++ b/cli/tests/testdata/test/ops_sanitizer_multiple_timeout_tests.out
@@ -0,0 +1,57 @@
+Check [WILDCARD]/testdata/test/ops_sanitizer_multiple_timeout_tests.ts
+running 2 tests from [WILDCARD]/testdata/test/ops_sanitizer_multiple_timeout_tests.ts
+test test 1 ... FAILED ([WILDCARD])
+test test 2 ... FAILED ([WILDCARD])
+
+failures:
+
+test 1
+AssertionError: Test case is leaking async ops.
+Before:
+ - dispatched: 0
+ - completed: 0
+After:
+ - dispatched: [WILDCARD]
+ - completed: [WILDCARD]
+Ops:
+ op_sleep:
+ Before:
+ - dispatched: 0
+ - completed: 0
+ After:
+ - dispatched: [WILDCARD]
+ - completed: [WILDCARD]
+
+Make sure to await all promises returned from Deno APIs before
+finishing test case.
+ at [WILDCARD]
+
+test 2
+AssertionError: Test case is leaking async ops.
+Before:
+ - dispatched: [WILDCARD]
+ - completed: [WILDCARD]
+After:
+ - dispatched: [WILDCARD]
+ - completed: [WILDCARD]
+Ops:
+ op_sleep:
+ Before:
+ - dispatched: [WILDCARD]
+ - completed: [WILDCARD]
+ After:
+ - dispatched: [WILDCARD]
+ - completed: [WILDCARD]
+
+Make sure to await all promises returned from Deno APIs before
+finishing test case.
+ at [WILDCARD]
+
+failures:
+
+ test 1
+ test 2
+
+test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out ([WILDCARD])
+
+error: Test failed
diff --git a/cli/tests/testdata/test/ops_sanitizer_multiple_timeout_tests.ts b/cli/tests/testdata/test/ops_sanitizer_multiple_timeout_tests.ts
new file mode 100644
index 000000000..f30773cf2
--- /dev/null
+++ b/cli/tests/testdata/test/ops_sanitizer_multiple_timeout_tests.ts
@@ -0,0 +1,10 @@
+// https://github.com/denoland/deno/issues/8965
+
+function test() {
+ setTimeout(() => {}, 10000);
+ setTimeout(() => {}, 10001);
+}
+
+Deno.test("test 1", test);
+
+Deno.test("test 2", test);
diff --git a/cli/tests/testdata/test/ops_sanitizer_unstable.out b/cli/tests/testdata/test/ops_sanitizer_unstable.out
index 3faea472b..9d6a903e1 100644
--- a/cli/tests/testdata/test/ops_sanitizer_unstable.out
+++ b/cli/tests/testdata/test/ops_sanitizer_unstable.out
@@ -11,16 +11,16 @@ Before:
- dispatched: 1
- completed: 1
After:
- - dispatched: 3
- - completed: 2
+ - dispatched: [WILDCARD]
+ - completed: [WILDCARD]
Ops:
- op_global_timer:
+ op_sleep:
Before:
- dispatched: 1
- completed: 1
After:
- - dispatched: 3
- - completed: 2
+ - dispatched: [WILDCARD]
+ - completed: [WILDCARD]
Make sure to await all promises returned from Deno APIs before
finishing test case.
diff --git a/cli/tests/testdata/worker_drop_handle_race.js.out b/cli/tests/testdata/worker_drop_handle_race.js.out
index 271e07854..b7218e8f6 100644
--- a/cli/tests/testdata/worker_drop_handle_race.js.out
+++ b/cli/tests/testdata/worker_drop_handle_race.js.out
@@ -2,7 +2,7 @@ error: Uncaught (in worker "") Error
throw new Error();
^
at [WILDCARD]/workers/drop_handle_race.js:2:9
- at fire (deno:ext/timers/[WILDCARD])
+ at Object.action (deno:ext/timers/[WILDCARD])
at handleTimerMacrotask (deno:ext/timers/[WILDCARD])
error: Uncaught (in promise) Error: Unhandled error event in child worker.
at Worker.#pollControl (deno:runtime/js/11_workers.js:[WILDCARD])
diff --git a/cli/tests/unit/timers_test.ts b/cli/tests/unit/timers_test.ts
index 35a21297f..fc6f9af4d 100644
--- a/cli/tests/unit/timers_test.ts
+++ b/cli/tests/unit/timers_test.ts
@@ -6,6 +6,7 @@ import {
Deferred,
deferred,
delay,
+ unreachable,
} from "./test_util.ts";
Deno.test(async function functionParameterBindingSuccess() {
@@ -206,6 +207,60 @@ Deno.test(function intervalCancelInvalidSilentFail() {
clearInterval(2147483647);
});
+Deno.test(async function callbackTakesLongerThanInterval() {
+ const promise = deferred();
+
+ let timeEndOfFirstCallback: number | undefined;
+ const interval = setInterval(() => {
+ if (timeEndOfFirstCallback === undefined) {
+ // First callback
+ Deno.sleepSync(300);
+ timeEndOfFirstCallback = Date.now();
+ } else {
+ // Second callback
+ assert(Date.now() - 100 >= timeEndOfFirstCallback);
+ clearInterval(interval);
+ promise.resolve();
+ }
+ }, 100);
+
+ await promise;
+});
+
+// https://github.com/denoland/deno/issues/11398
+Deno.test(async function clearTimeoutAfterNextTimerIsDue1() {
+ const promise = deferred();
+
+ setTimeout(() => {
+ promise.resolve();
+ }, 300);
+
+ const interval = setInterval(() => {
+ Deno.sleepSync(400);
+ // Both the interval and the timeout's due times are now in the past.
+ clearInterval(interval);
+ }, 100);
+
+ await promise;
+});
+
+// https://github.com/denoland/deno/issues/11398
+Deno.test(async function clearTimeoutAfterNextTimerIsDue2() {
+ const promise = deferred();
+
+ const timeout1 = setTimeout(unreachable, 100);
+
+ setTimeout(() => {
+ promise.resolve();
+ }, 200);
+
+ Deno.sleepSync(300);
+ // Both of the timeouts' due times are now in the past.
+ clearTimeout(timeout1);
+
+ await promise;
+});
+
Deno.test(async function fireCallbackImmediatelyWhenDelayOverMaxValue() {
let count = 0;
setTimeout(() => {
@@ -346,6 +401,35 @@ Deno.test(async function timerMaxCpuBug() {
assert(opsDispatched_ - opsDispatched < 10);
});
+Deno.test(async function timerOrdering() {
+ const array: number[] = [];
+ const donePromise = deferred();
+
+ function push(n: number) {
+ array.push(n);
+ if (array.length === 6) {
+ donePromise.resolve();
+ }
+ }
+
+ setTimeout(() => {
+ push(1);
+ setTimeout(() => push(4));
+ }, 0);
+ setTimeout(() => {
+ push(2);
+ setTimeout(() => push(5));
+ }, 0);
+ setTimeout(() => {
+ push(3);
+ setTimeout(() => push(6));
+ }, 0);
+
+ await donePromise;
+
+ assertEquals(array, [1, 2, 3, 4, 5, 6]);
+});
+
Deno.test(async function timerBasicMicrotaskOrdering() {
let s = "";
let count = 0;