Skip to content

Commit

Permalink
chore: fix flaky rejection_handled_web_process (#23817)
Browse files Browse the repository at this point in the history
Closes #23712
  • Loading branch information
dsherret committed May 14, 2024
1 parent e389917 commit 1a788b5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
9 changes: 0 additions & 9 deletions tests/integration/node_unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,3 @@ itest!(unhandled_rejection_web_process {
envs: env_vars_for_npm_tests(),
http_server: true,
});

// Ensure that Web `onrejectionhandled` is fired before
// Node's `process.on('rejectionHandled')`.
itest!(rejection_handled_web_process {
args: "run -A --quiet node/rejection_handled_web_process.ts",
output: "node/rejection_handled_web_process.ts.out",
envs: env_vars_for_npm_tests(),
http_server: true,
});
6 changes: 6 additions & 0 deletions tests/specs/node/rejection_handled_web_process/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Ensure that Web `onrejectionhandled` is fired before
// Node's `process.on('rejectionHandled')`.
{
"args": "run -A --quiet rejection_handled_web_process.ts",
"output": "rejection_handled_web_process.ts.out"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import process from "node:process";

console.log(chalk.red("Hello world!"));

const { promise, resolve } = Promise.withResolvers();

globalThis.addEventListener("unhandledrejection", (e) => {
console.log('globalThis.addEventListener("unhandledrejection");');
e.preventDefault();
Expand All @@ -14,13 +16,20 @@ globalThis.addEventListener("rejectionhandled", (_) => {

process.on("rejectionHandled", (_) => {
console.log("Node rejectionHandled");
resolve();
});

const a = Promise.reject(1);
setTimeout(() => {
a.catch(() => console.log("Added catch handler to the promise"));
}, 100);

setTimeout(() => {
const exitTimeout = setTimeout(() => {
console.error("timeout expired");
Deno.exit(1);
}, 30_000);

promise.then(() => {
console.log("Success");
}, 1000);
clearTimeout(exitTimeout);
});
2 changes: 1 addition & 1 deletion tools/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ async function ensureNoNewITests() {
// Read the comment above. Please don't increase these numbers!
"lsp_tests.rs": 0,
"node_compat_tests.rs": 4,
"node_unit_tests.rs": 3,
"node_unit_tests.rs": 2,
"npm_tests.rs": 98,
"pm_tests.rs": 0,
"publish_tests.rs": 0,
Expand Down

0 comments on commit 1a788b5

Please sign in to comment.