fix(runtime/testing): false positive for timers when an error is thrown (#9553)

This commit is contained in:
Casper Beyer 2021-02-22 00:21:25 +08:00 committed by GitHub
parent b47f9cee8c
commit eefd522f04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 5 deletions

View file

@ -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.