mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00

Use assert.strictEqual instead of assert.equal in tests, manually convert types where necessary. PR-URL: https://github.com/nodejs/node/pull/10698 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
let name;
|
|
const max = 3;
|
|
let count = 0;
|
|
|
|
const server = http.Server(function(req, res) {
|
|
if (req.url === '/0') {
|
|
setTimeout(function() {
|
|
res.writeHead(200);
|
|
res.end('Hello, World!');
|
|
}, 100);
|
|
} else {
|
|
res.writeHead(200);
|
|
res.end('Hello, World!');
|
|
}
|
|
});
|
|
server.listen(0, function() {
|
|
name = http.globalAgent.getName({ port: this.address().port });
|
|
for (let i = 0; i < max; ++i) {
|
|
request(i);
|
|
}
|
|
});
|
|
|
|
function request(i) {
|
|
const req = http.get({
|
|
port: server.address().port,
|
|
path: '/' + i
|
|
}, function(res) {
|
|
const socket = req.socket;
|
|
socket.on('close', function() {
|
|
++count;
|
|
if (count < max) {
|
|
assert.strictEqual(http.globalAgent.sockets[name].indexOf(socket), -1);
|
|
} else {
|
|
assert(!http.globalAgent.sockets.hasOwnProperty(name));
|
|
assert(!http.globalAgent.requests.hasOwnProperty(name));
|
|
server.close();
|
|
}
|
|
});
|
|
res.resume();
|
|
});
|
|
}
|
|
|
|
process.on('exit', function() {
|
|
assert.strictEqual(count, max);
|
|
});
|