Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4f0cdae

Browse filesBrowse files
daxlabgibfahn
authored andcommitted
test: Update test-http-client-agent to use countdown timer
PR-URL: #17325 Refs: #17169 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 2d7e03f commit 4f0cdae
Copy full SHA for 4f0cdae

File tree

Expand file treeCollapse file tree

1 file changed

+9
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-7
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http-client-agent.js
+9-7Lines changed: 9 additions & 7 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.