mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 04:48:52 -05:00
fix(test): handle scenario where --trace-ops would cause an unhandled promise rejection (#16970)
Closes #16969
This commit is contained in:
parent
c03e0f3853
commit
5dbc07935d
4 changed files with 29 additions and 3 deletions
|
@ -227,6 +227,12 @@ mod test {
|
||||||
output: "test/ops_sanitizer_multiple_timeout_tests_no_trace.out",
|
output: "test/ops_sanitizer_multiple_timeout_tests_no_trace.out",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(trace_ops_catch_error {
|
||||||
|
args: "test -A --trace-ops test/trace_ops_caught_error/main.ts",
|
||||||
|
exit_code: 0,
|
||||||
|
output: "test/trace_ops_caught_error/main.out",
|
||||||
|
});
|
||||||
|
|
||||||
// TODO(@littledivy): re-enable this test, recent optimizations made output non deterministic.
|
// TODO(@littledivy): re-enable this test, recent optimizations made output non deterministic.
|
||||||
// https://github.com/denoland/deno/issues/14268
|
// https://github.com/denoland/deno/issues/14268
|
||||||
//
|
//
|
||||||
|
|
6
cli/tests/testdata/test/trace_ops_caught_error/main.out
vendored
Normal file
6
cli/tests/testdata/test/trace_ops_caught_error/main.out
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
Check file:///[WILDCARD]/trace_ops_caught_error/main.ts
|
||||||
|
running 1 test from ./test/trace_ops_caught_error/main.ts
|
||||||
|
handle thrown error in async function ... ok ([WILDCARD])
|
||||||
|
|
||||||
|
ok | 1 passed | 0 failed ([WILDCARD])
|
||||||
|
|
12
cli/tests/testdata/test/trace_ops_caught_error/main.ts
vendored
Normal file
12
cli/tests/testdata/test/trace_ops_caught_error/main.ts
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
Deno.test("handle thrown error in async function", async () => {
|
||||||
|
const dirPath = Deno.makeTempDirSync();
|
||||||
|
const filePath = `${dirPath}/file.txt`;
|
||||||
|
try {
|
||||||
|
await Deno.stat(filePath);
|
||||||
|
} catch {
|
||||||
|
await Deno.writeTextFile(filePath, "");
|
||||||
|
} finally {
|
||||||
|
await Deno.remove(filePath);
|
||||||
|
await Deno.remove(dirPath);
|
||||||
|
}
|
||||||
|
});
|
|
@ -187,7 +187,7 @@
|
||||||
// Rethrow the error
|
// Rethrow the error
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
handleOpCallTracing("${name}", id, promise);
|
promise = handleOpCallTracing("${name}", id, promise);
|
||||||
promise[promiseIdSymbol] = id;
|
promise[promiseIdSymbol] = id;
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
@ -218,10 +218,12 @@
|
||||||
if (opCallTracingEnabled) {
|
if (opCallTracingEnabled) {
|
||||||
const stack = StringPrototypeSlice(new Error().stack, 6);
|
const stack = StringPrototypeSlice(new Error().stack, 6);
|
||||||
MapPrototypeSet(opCallTraces, promiseId, { opName, stack });
|
MapPrototypeSet(opCallTraces, promiseId, { opName, stack });
|
||||||
p = PromisePrototypeFinally(
|
return PromisePrototypeFinally(
|
||||||
p,
|
p,
|
||||||
() => MapPrototypeDelete(opCallTraces, promiseId),
|
() => MapPrototypeDelete(opCallTraces, promiseId),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue