Skip to content

Commit 4a749c3

Browse files
daxlabMylesBorins
authored andcommitted
test: Update test-http-client-agent to use countdown timer
PR-URL: #17325 Refs: #17169 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 5a4b6c4 commit 4a749c3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

test/parallel/test-http-client-agent.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
const common = require('../common');
2424
const assert = require('assert');
2525
const http = require('http');
26+
const Countdown = require('../common/countdown');
2627

2728
let name;
2829
const max = 3;
29-
let count = 0;
3030

3131
const server = http.Server(common.mustCall((req, res) => {
3232
if (req.url === '/0') {
@@ -45,21 +45,23 @@ server.listen(0, common.mustCall(() => {
4545
request(i);
4646
}));
4747

48+
const countdown = new Countdown(max, () => {
49+
assert(!http.globalAgent.sockets.hasOwnProperty(name));
50+
assert(!http.globalAgent.requests.hasOwnProperty(name));
51+
server.close();
52+
});
53+
4854
function request(i) {
4955
const req = http.get({
5056
port: server.address().port,
5157
path: `/${i}`
5258
}, function(res) {
5359
const socket = req.socket;
5460
socket.on('close', common.mustCall(() => {
55-
++count;
56-
if (count < max) {
61+
countdown.dec();
62+
if (countdown.remaining > 0) {
5763
assert.strictEqual(http.globalAgent.sockets[name].includes(socket),
5864
false);
59-
} else {
60-
assert(!http.globalAgent.sockets.hasOwnProperty(name));
61-
assert(!http.globalAgent.requests.hasOwnProperty(name));
62-
server.close();
6365
}
6466
}));
6567
res.resume();

0 commit comments

Comments
 (0)