From 851f795001a9164572d02606587ddc5193bdfd2d Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Thu, 14 Sep 2023 16:38:15 +0200 Subject: fix: output traces for op sanitizer in more cases (#20494) This adds traces for the "started outside test, closed inside test" case. --- cli/js/40_testing.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'cli/js') diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js index 37eb6be8f..443b91596 100644 --- a/cli/js/40_testing.js +++ b/cli/js/40_testing.js @@ -206,15 +206,30 @@ function assertOps(fn) { } else if (dispatchedDiff < completedDiff) { const [name, hint] = OP_DETAILS[key] || [key, null]; const count = completedDiff - dispatchedDiff; - ArrayPrototypePush( - details, - `${count} async operation${count === 1 ? "" : "s"} to ${name} ${ - count === 1 ? "was" : "were" - } started before this test, but ${ - count === 1 ? "was" : "were" - } completed during the test. Async operations should not complete in a test if they were not started in that test. - ${hint ? `This is often caused by not ${hint}.` : ""}`, - ); + let message = `${count} async operation${ + count === 1 ? "" : "s" + } to ${name} ${ + count === 1 ? "was" : "were" + } started before this test, but ${ + count === 1 ? "was" : "were" + } completed during the test. Async operations should not complete in a test if they were not started in that test.`; + if (hint) { + message += ` This is often caused by not ${hint}.`; + } + const traces = []; + for (const [id, { opName, stack }] of preTraces) { + if (opName !== key) continue; + if (MapPrototypeHas(postTraces, id)) continue; + ArrayPrototypePush(traces, stack); + } + if (traces.length === 1) { + message += " The operation was started here:\n"; + message += traces[0]; + } else if (traces.length > 1) { + message += " The operations were started here:\n"; + message += ArrayPrototypeJoin(traces, "\n\n"); + } + ArrayPrototypePush(details, message); } } return { failed: { leakedOps: [details, core.isOpCallTracingEnabled()] } }; -- cgit v1.2.3