test: use Countdown in http test

PR-URL: https://github.com/nodejs/node/pull/17506
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
idandagan1 2017-12-06 21:57:13 +02:00 committed by Anatoli Papirovski
parent 5279035d93
commit 20d6b8c6c0
No known key found for this signature in database
GPG Key ID: 614E2E1ABEB4B2C0

View File

@ -21,11 +21,13 @@
'use strict';
const common = require('../common');
const Countdown = require('../common/countdown');
const http = require('http');
const net = require('net');
const seeds = [ 3, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 ];
const countdown = new Countdown(seeds.length, () => server.close());
// Set up some timing issues where sockets can be destroyed
// via either the req or res.
@ -72,11 +74,8 @@ function generator(seeds) {
server.listen(0, common.mustCall(function() {
const client = net.connect({ port: this.address().port });
let done = 0;
server.on('requestDone', function() {
if (++done === seeds.length) {
server.close();
}
countdown.dec();
});
// immediately write the pipelined requests.