mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 15:41:06 +00:00

Converted the 'message' argument values from the last two free socket assert.strictEqual() calls to code comments as they fail to provide the necessary details and values specific to why the test is failing. The default message returned from the strictEqual() call should provide sufficient details for debugging errors. PR-URL: https://github.com/nodejs/node/pull/19525 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
const Agent = http.Agent;
|
|
|
|
const server = http.createServer(common.mustCall((req, res) => {
|
|
res.end('hello world');
|
|
}, 2));
|
|
|
|
server.listen(0, () => {
|
|
const agent = new Agent({ keepAlive: true });
|
|
|
|
const requestParams = {
|
|
host: 'localhost',
|
|
port: server.address().port,
|
|
agent: agent,
|
|
path: '/'
|
|
};
|
|
|
|
const socketKey = agent.getName(requestParams);
|
|
|
|
http.get(requestParams, common.mustCall((res) => {
|
|
assert.strictEqual(res.statusCode, 200);
|
|
res.resume();
|
|
res.on('end', common.mustCall(() => {
|
|
process.nextTick(common.mustCall(() => {
|
|
const freeSockets = agent.freeSockets[socketKey];
|
|
//expect a free socket on socketKey
|
|
assert.strictEqual(freeSockets.length, 1);
|
|
|
|
//generate a random error on the free socket
|
|
const freeSocket = freeSockets[0];
|
|
freeSocket.emit('error', new Error('ECONNRESET: test'));
|
|
|
|
http.get(requestParams, done);
|
|
}));
|
|
}));
|
|
}));
|
|
|
|
function done() {
|
|
//expect the freeSockets pool to be empty
|
|
assert.strictEqual(Object.keys(agent.freeSockets).length, 0);
|
|
|
|
agent.destroy();
|
|
server.close();
|
|
}
|
|
});
|