Skip to content

Commit

Permalink
test: update test-http-timeout to use countdown
Browse files Browse the repository at this point in the history
PR-URL: #17341
Reviewed-By: Jon Moss <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
  • Loading branch information
mithunsasidharan authored and MylesBorins committed Dec 12, 2017
1 parent 9cbb0da commit 69e775d
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions test/parallel/test-http-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,33 @@
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 },
function(res) {
req.clearTimeout(callback);

res.on('end', function() {
count++;

if (count === 11) {
server.close();
}
countdown.dec();
});

res.resume();
Expand Down

0 comments on commit 69e775d

Please sign in to comment.