test: Update test-http-client-agent to use countdown timer
PR-URL: https://github.com/nodejs/node/pull/17325 Refs: https://github.com/nodejs/node/issues/17169 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
aec9149c1e
commit
3996da6d26
@ -23,10 +23,10 @@
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
const Countdown = require('../common/countdown');
|
||||
|
||||
let name;
|
||||
const max = 3;
|
||||
let count = 0;
|
||||
|
||||
const server = http.Server(common.mustCall((req, res) => {
|
||||
if (req.url === '/0') {
|
||||
@ -45,6 +45,12 @@ server.listen(0, common.mustCall(() => {
|
||||
request(i);
|
||||
}));
|
||||
|
||||
const countdown = new Countdown(max, () => {
|
||||
assert(!http.globalAgent.sockets.hasOwnProperty(name));
|
||||
assert(!http.globalAgent.requests.hasOwnProperty(name));
|
||||
server.close();
|
||||
});
|
||||
|
||||
function request(i) {
|
||||
const req = http.get({
|
||||
port: server.address().port,
|
||||
@ -52,14 +58,10 @@ function request(i) {
|
||||
}, function(res) {
|
||||
const socket = req.socket;
|
||||
socket.on('close', common.mustCall(() => {
|
||||
++count;
|
||||
if (count < max) {
|
||||
countdown.dec();
|
||||
if (countdown.remaining > 0) {
|
||||
assert.strictEqual(http.globalAgent.sockets[name].includes(socket),
|
||||
false);
|
||||
} else {
|
||||
assert(!http.globalAgent.sockets.hasOwnProperty(name));
|
||||
assert(!http.globalAgent.requests.hasOwnProperty(name));
|
||||
server.close();
|
||||
}
|
||||
}));
|
||||
res.resume();
|
||||
|
Loading…
x
Reference in New Issue
Block a user