Skip to content

Commit 956198f

Browse files
daxlabgibfahn
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 3eab248 commit 956198f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
const common = require('../common');
33
const assert = require('assert');
44
const http = require('http');
5+
const Countdown = require('../common/countdown');
56

67
let name;
78
const max = 3;
8-
let count = 0;
99

1010
const server = http.Server(common.mustCall((req, res) => {
1111
if (req.url === '/0') {
@@ -24,21 +24,23 @@ server.listen(0, common.mustCall(() => {
2424
request(i);
2525
}));
2626

27+
const countdown = new Countdown(max, () => {
28+
assert(!http.globalAgent.sockets.hasOwnProperty(name));
29+
assert(!http.globalAgent.requests.hasOwnProperty(name));
30+
server.close();
31+
});
32+
2733
function request(i) {
2834
const req = http.get({
2935
port: server.address().port,
3036
path: `/${i}`
3137
}, function(res) {
3238
const socket = req.socket;
3339
socket.on('close', common.mustCall(() => {
34-
++count;
35-
if (count < max) {
40+
countdown.dec();
41+
if (countdown.remaining > 0) {
3642
assert.strictEqual(http.globalAgent.sockets[name].includes(socket),
3743
false);
38-
} else {
39-
assert(!http.globalAgent.sockets.hasOwnProperty(name));
40-
assert(!http.globalAgent.requests.hasOwnProperty(name));
41-
server.close();
4244
}
4345
}));
4446
res.resume();

0 commit comments

Comments
 (0)