diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-04-03 19:20:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-03 19:20:36 +0200 |
commit | 3f489ae1aeff6f27b2214dc8201ed068abd5f973 (patch) | |
tree | 87f0003df9dcca167beabfff83781445649db84c /cli/js/testing.ts | |
parent | efb022a50c8fd4ab598c0bdc6ff0c1978779260a (diff) |
fix: async ops sanitizer false positives in timers (#4602)
Diffstat (limited to 'cli/js/testing.ts')
-rw-r--r-- | cli/js/testing.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/cli/js/testing.ts b/cli/js/testing.ts index 5769495b2..542e1d065 100644 --- a/cli/js/testing.ts +++ b/cli/js/testing.ts @@ -14,6 +14,12 @@ const GREEN_OK = green("ok"); const YELLOW_IGNORED = yellow("ignored"); const disabledConsole = new Console((): void => {}); +function delay(n: number): Promise<void> { + return new Promise((resolve: () => void, _) => { + setTimeout(resolve, n); + }); +} + function formatDuration(time = 0): string { const timeStr = `(${time}ms)`; return gray(italic(timeStr)); @@ -28,6 +34,10 @@ function assertOps(fn: () => void | Promise<void>): () => void | Promise<void> { return async function asyncOpSanitizer(): Promise<void> { 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); 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. |