diff options
author | Bert Belder <bertbelder@gmail.com> | 2018-10-08 19:52:16 +0200 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2018-10-08 19:54:32 +0200 |
commit | 5b66f28fa3041b57d1c5e4c54d07bf78e7ee8c0c (patch) | |
tree | 80be5f26351a7fbfca5d149bba9ba0fe47fe8058 /js/timers_test.ts | |
parent | 3fe6530f118c36fd2b0268a4591fef540f8f6f1f (diff) |
timers: add test for clearTimer bug #942
Diffstat (limited to 'js/timers_test.ts')
-rw-r--r-- | js/timers_test.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/js/timers_test.ts b/js/timers_test.ts index 56cc56a9b..8d5245f11 100644 --- a/js/timers_test.ts +++ b/js/timers_test.ts @@ -65,6 +65,31 @@ test(async function timeoutCancelSuccess() { assertEqual(count, 0); }); +test(async function timeoutCancelMultiple() { + // Set timers and cancel them in the same order. + const t1 = setTimeout(uncalled, 10); + const t2 = setTimeout(uncalled, 10); + const t3 = setTimeout(uncalled, 10); + clearTimeout(t1); + clearTimeout(t2); + clearTimeout(t3); + + // Set timers and cancel them in reverse order. + const t4 = setTimeout(uncalled, 20); + const t5 = setTimeout(uncalled, 20); + const t6 = setTimeout(uncalled, 20); + clearTimeout(t6); + clearTimeout(t5); + clearTimeout(t4); + + // Sleep until we're certain that the cancelled timers aren't gonna fire. + await waitForMs(50); + + function uncalled() { + throw new Error("This function should not be called."); + } +}); + test(async function timeoutCancelInvalidSilentFail() { // Expect no panic const { promise, resolve } = deferred(); |