From 6f54b7f75496f242a83d3475ad764fae942a9cbb Mon Sep 17 00:00:00 2001 From: Mithun Sasidharan Date: Sun, 3 Dec 2017 23:23:33 +0530 Subject: [PATCH] test : refactored to use countdown --- test/parallel/test-http-timeout.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-http-timeout.js b/test/parallel/test-http-timeout.js index 817bfe7a3c3be7..c576f1c5429101 100644 --- a/test/parallel/test-http-timeout.js +++ b/test/parallel/test-http-timeout.js @@ -23,24 +23,25 @@ require('../common'); const http = require('http'); +const Countdown = require('../common/countdown'); const server = http.createServer(function(req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('OK'); }); +const MAX_COUNT = 11; const agent = new http.Agent({ maxSockets: 1 }); +const countdown = new Countdown(MAX_COUNT, () => server.close()); server.listen(0, function() { - for (let i = 0; i < 11; ++i) { + for (let i = 0; i < MAX_COUNT; ++i) { createRequest().end(); } function callback() {} - let count = 0; - function createRequest() { const req = http.request( { port: server.address().port, path: '/', agent: agent }, @@ -48,11 +49,7 @@ server.listen(0, function() { req.clearTimeout(callback); res.on('end', function() { - count++; - - if (count === 11) { - server.close(); - } + countdown.dec(); }); res.resume();