Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 13 additions & 35 deletions test/parallel/test-tls-psk-alpn-callback-exception-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ describe('TLS callback exception handling', () => {
reject(e);
}
}));

server.on('secureConnection', () => {
reject(new Error('secureConnection should not fire'));
});
server.on('secureConnection', common.mustNotCall('secureConnection listener'));

await new Promise((res) => server.listen(0, res));

Expand All @@ -112,7 +109,7 @@ describe('TLS callback exception handling', () => {
}),
});

client.on('error', () => {});
client.on('error', common.mustCall());

await promise;
});
Expand Down Expand Up @@ -142,9 +139,6 @@ describe('TLS callback exception handling', () => {
}
}));

server.on('secureConnection', () => {
reject(new Error('secureConnection should not fire'));
});

await new Promise((res) => server.listen(0, res));

Expand All @@ -159,7 +153,7 @@ describe('TLS callback exception handling', () => {
}),
});

client.on('error', () => {});
client.on('error', common.mustCall());

await promise;
});
Expand Down Expand Up @@ -189,10 +183,7 @@ describe('TLS callback exception handling', () => {
reject(e);
}
}));

server.on('secureConnection', () => {
reject(new Error('secureConnection should not fire'));
});
server.on('secureConnection', common.mustNotCall('secureConnection listener'));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this fires while promise is being awaited at the end of the test function, and tlsClientError doesn't fire? Seems like the event will be handled outside of the test's promise task, promise won't be resolved or rejected, and the test will hang until timeout?

@aduh95 aduh95 Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node/test/common/index.js

Lines 563 to 572 in 5922197

function mustNotCall(msg) {
const callSite = getCallSites()[1];
return function mustNotCall(...args) {
const argsInfo = args.length > 0 ?
`\ncalled with arguments: ${args.map((arg) => inspect(arg)).join(', ')}` : '';
assert.fail(
`${msg || 'function should not have been called'} at ${callSite.scriptName}:${callSite.lineNumber}` +
argsInfo);
};
}

It would throw an unhandled rejection which would terminate the process immediately
In any case, a pending promise is not enough to keep the process alive, so no the test won't hang


await new Promise((res) => server.listen(0, res));

Expand All @@ -203,7 +194,7 @@ describe('TLS callback exception handling', () => {
ALPNProtocols: ['http/1.1', 'h2'],
});

client.on('error', () => {});
client.on('error', common.mustCall());

await promise;
});
Expand Down Expand Up @@ -232,10 +223,7 @@ describe('TLS callback exception handling', () => {
reject(e);
}
}));

server.on('secureConnection', () => {
reject(new Error('secureConnection should not fire'));
});
server.on('secureConnection', common.mustNotCall('secureConnection listener'));

await new Promise((res) => server.listen(0, res));

Expand All @@ -246,7 +234,7 @@ describe('TLS callback exception handling', () => {
ALPNProtocols: ['http/1.1'],
});

client.on('error', () => {});
client.on('error', common.mustCall());

await promise;
});
Expand All @@ -265,9 +253,7 @@ describe('TLS callback exception handling', () => {

const { promise, resolve, reject } = createTestPromise();

server.on('secureConnection', () => {
reject(new Error('secureConnection should not fire'));
});
server.on('secureConnection', common.mustNotCall('secureConnection listener'));

await new Promise((res) => server.listen(0, res));

Expand Down Expand Up @@ -309,9 +295,7 @@ describe('TLS callback exception handling', () => {

const { promise, resolve, reject } = createTestPromise();

server.on('secureConnection', () => {
reject(new Error('secureConnection should not fire'));
});
server.on('secureConnection', common.mustNotCall('secureConnection listener'));

await new Promise((res) => server.listen(0, res));

Expand Down Expand Up @@ -362,10 +346,7 @@ describe('TLS callback exception handling', () => {
reject(e);
}
}));

server.on('secureConnection', () => {
reject(new Error('secureConnection should not fire'));
});
server.on('secureConnection', common.mustNotCall('secureConnection listener'));

await new Promise((res) => server.listen(0, res));

Expand All @@ -376,7 +357,7 @@ describe('TLS callback exception handling', () => {
rejectUnauthorized: false,
});

client.on('error', () => {});
client.on('error', common.mustCall());

await promise;
});
Expand Down Expand Up @@ -409,10 +390,7 @@ describe('TLS callback exception handling', () => {
reject(e);
}
}));

server.on('secureConnection', () => {
reject(new Error('secureConnection should not fire'));
});
server.on('secureConnection', common.mustNotCall('secureConnection listener'));

await new Promise((res) => server.listen(0, res));

Expand All @@ -423,7 +401,7 @@ describe('TLS callback exception handling', () => {
rejectUnauthorized: false,
});

client.on('error', () => {});
client.on('error', common.mustCall());

await promise;
});
Expand Down
Loading