summaryrefslogtreecommitdiff
path: root/runtime/js/40_testing.js
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-10-11 23:00:33 +0800
committerGitHub <noreply@github.com>2021-10-11 17:00:33 +0200
commit1683044ed97953cb1dbfc0080440d5c4cc47bd2e (patch)
treee23604c28b8988f76984189c23f88b73415935a1 /runtime/js/40_testing.js
parent3b2cb8e7113b19344209eddc8bc1bd447fcec4ea (diff)
feat: provide ops details for ops sanitizer failures (#12188)
Diffstat (limited to 'runtime/js/40_testing.js')
-rw-r--r--runtime/js/40_testing.js37
1 files changed, 33 insertions, 4 deletions
diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js
index 2adb487fb..1fec58196 100644
--- a/runtime/js/40_testing.js
+++ b/runtime/js/40_testing.js
@@ -23,6 +23,7 @@
StringPrototypeIncludes,
StringPrototypeSlice,
RegExp,
+ Number,
RegExpPrototypeTest,
SymbolToStringTag,
} = window.__bootstrap.primordials;
@@ -46,22 +47,50 @@
}
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.
const dispatchedDiff = post.opsDispatchedAsync - pre.opsDispatchedAsync;
const completedDiff = post.opsCompletedAsync - pre.opsCompletedAsync;
- assert(
- dispatchedDiff === completedDiff,
- `Test case is leaking async ops.
+
+ const details = [];
+ for (const key in post.ops) {
+ const dispatchedDiff = Number(
+ post.ops[key]?.opsDispatchedAsync -
+ (pre.ops[key]?.opsDispatchedAsync ?? 0),
+ );
+ const completedDiff = Number(
+ post.ops[key]?.opsCompletedAsync -
+ (pre.ops[key]?.opsCompletedAsync ?? 0),
+ );
+
+ if (dispatchedDiff !== completedDiff) {
+ details.push(`
+ ${key}:
+ Before:
+ - dispatched: ${pre.ops[key]?.opsDispatchedAsync ?? 0}
+ - completed: ${pre.ops[key]?.opsCompletedAsync ?? 0}
+ After:
+ - dispatched: ${post.ops[key].opsDispatchedAsync}
+ - completed: ${post.ops[key].opsCompletedAsync}`);
+ }
+ }
+
+ const message = `Test case is leaking async ops.
Before:
- dispatched: ${pre.opsDispatchedAsync}
- completed: ${pre.opsCompletedAsync}
After:
- dispatched: ${post.opsDispatchedAsync}
- completed: ${post.opsCompletedAsync}
+${details.length > 0 ? "Ops:" + details.join("") : ""}
Make sure to await all promises returned from Deno APIs before
-finishing test case.`,
+finishing test case.`;
+
+ assert(
+ dispatchedDiff === completedDiff,
+ message,
);
};
}