diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2019-12-03 19:19:03 -0800 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-12-03 22:19:03 -0500 |
commit | 32937251315493ef2c3b42dd29340e8a34501aa4 (patch) | |
tree | fabe0bfda91c9c1d7fef22106e1b5659152c949d /cli/js/timers_test.ts | |
parent | 91da410fc3bfde76c3c8930c6f8bfd4d5f9b974e (diff) |
Timer/microtask ordering fix (#3439)
Diffstat (limited to 'cli/js/timers_test.ts')
-rw-r--r-- | cli/js/timers_test.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/cli/js/timers_test.ts b/cli/js/timers_test.ts index b928dcac1..ba938f850 100644 --- a/cli/js/timers_test.ts +++ b/cli/js/timers_test.ts @@ -299,3 +299,55 @@ test(async function timerMaxCpuBug(): Promise<void> { console.log("opsDispatched", opsDispatched, "opsDispatched_", opsDispatched_); assert(opsDispatched_ - opsDispatched < 10); }); + +test(async function timerBasicMicrotaskOrdering(): Promise<void> { + let s = ""; + let count = 0; + const { promise, resolve } = deferred(); + setTimeout(() => { + Promise.resolve().then(() => { + count++; + s += "de"; + if (count === 2) { + resolve(); + } + }); + }); + setTimeout(() => { + count++; + s += "no"; + if (count === 2) { + resolve(); + } + }); + await promise; + assertEquals(s, "deno"); +}); + +test(async function timerNestedMicrotaskOrdering(): Promise<void> { + let s = ""; + const { promise, resolve } = deferred(); + s += "0"; + setTimeout(() => { + s += "4"; + setTimeout(() => (s += "8")); + Promise.resolve().then(() => { + setTimeout(() => { + s += "9"; + resolve(); + }); + }); + }); + setTimeout(() => (s += "5")); + Promise.resolve().then(() => (s += "2")); + Promise.resolve().then(() => + setTimeout(() => { + s += "6"; + Promise.resolve().then(() => (s += "7")); + }) + ); + Promise.resolve().then(() => Promise.resolve().then(() => (s += "3"))); + s += "1"; + await promise; + assertEquals(s, "0123456789"); +}); |