Skip to content

Commit 69e775d

Browse files
mithunsasidharanMylesBorins
authored andcommitted
test: update test-http-timeout to use countdown
PR-URL: #17341 Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
1 parent 9cbb0da commit 69e775d

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

test/parallel/test-http-timeout.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,33 @@
2323
require('../common');
2424

2525
const http = require('http');
26+
const Countdown = require('../common/countdown');
2627

2728
const server = http.createServer(function(req, res) {
2829
res.writeHead(200, { 'Content-Type': 'text/plain' });
2930
res.end('OK');
3031
});
3132

33+
const MAX_COUNT = 11;
3234
const agent = new http.Agent({ maxSockets: 1 });
35+
const countdown = new Countdown(MAX_COUNT, () => server.close());
3336

3437
server.listen(0, function() {
3538

36-
for (let i = 0; i < 11; ++i) {
39+
for (let i = 0; i < MAX_COUNT; ++i) {
3740
createRequest().end();
3841
}
3942

4043
function callback() {}
4144

42-
let count = 0;
43-
4445
function createRequest() {
4546
const req = http.request(
4647
{ port: server.address().port, path: '/', agent: agent },
4748
function(res) {
4849
req.clearTimeout(callback);
4950

5051
res.on('end', function() {
51-
count++;
52-
53-
if (count === 11) {
54-
server.close();
55-
}
52+
countdown.dec();
5653
});
5754

5855
res.resume();

0 commit comments

Comments
 (0)