test: ensure assertions are reachable in test/client-proxy

PR-URL: https://github.com/nodejs/node/pull/60175
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
Antoine du Hamel 2025-10-12 22:43:10 +02:00 committed by GitHub
parent 2216a3b1d5
commit da9cd745c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 10 deletions

View File

@ -12,16 +12,16 @@ import { Worker } from 'node:worker_threads';
const expectedProxyLogs = new Set();
const proxyWorker = new Worker(fixtures.path('proxy-server-worker.js'));
proxyWorker.on('message', (message) => {
proxyWorker.on('message', common.mustCall((message) => {
console.log('Received message from worker:', message.type);
if (message.type === 'proxy-listening') {
startTest(message.port);
startTest(message.port).then(common.mustCall());
} else if (message.type === 'proxy-stopped') {
assert.deepStrictEqual(new Set(message.logs), expectedProxyLogs);
// Close the server after the proxy is stopped.
proxyWorker.terminate();
}
});
}, 2));
const requests = new Set();
// Create a server that records the requests it gets.
@ -74,7 +74,7 @@ async function startTest(proxyPort) {
'proxy-connection': 'close',
},
});
http.request(url, (res) => {
http.request(url, common.mustCall((res) => {
res.on('error', common.mustNotCall());
res.setEncoding('utf8');
res.on('data', () => {});
@ -88,6 +88,6 @@ async function startTest(proxyPort) {
proxyWorker.postMessage({ type: 'stop-proxy' });
}
}));
}).on('error', common.mustNotCall()).end();
})).on('error', common.mustNotCall()).end();
}
}

View File

@ -67,7 +67,7 @@ for (const testCase of testCases) {
url: severHost,
headers: { host: severHost },
});
https.request(url, (res) => {
https.request(url, common.mustCall((res) => {
res.on('error', common.mustNotCall());
res.setEncoding('utf8');
res.on('data', (data) => {
@ -77,14 +77,14 @@ for (const testCase of testCases) {
console.log(`[Proxy client] #${++counter} closed request for: ${inspect(url)}`);
// Finished all test cases.
if (counter === testCases.length) {
setImmediate(() => {
setImmediate(common.mustCall(() => {
console.log('All requests completed, shutting down.');
proxy.close();
server.close();
assert.deepStrictEqual(requests, expectedUrls);
assert.deepStrictEqual(new Set(logs), expectedProxyLogs);
});
}));
}
}));
}).on('error', common.mustNotCall()).end();
})).on('error', common.mustNotCall()).end();
}

View File

@ -156,7 +156,7 @@ export default [
},
{
files: [
'test/{async-hooks,message,module-hooks,node-api,pummel,pseudo-tty,v8-updates,wasi}/**/*.{js,mjs,cjs}',
'test/{async-hooks,benchmark,cctest,client-proxy,message,module-hooks,node-api,pummel,pseudo-tty,v8-updates,wasi}/**/*.{js,mjs,cjs}',
],
rules: {
'node-core/must-call-assert': 'error',