test: use Countdown in test-http-set-cookies

PR-URL: https://github.com/nodejs/node/pull/17504
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
This commit is contained in:
Shilo Mangam 2017-12-06 20:36:28 +02:00 committed by Anatoli Papirovski
parent 0a0fbd5498
commit 6a089f9357
No known key found for this signature in database
GPG Key ID: 614E2E1ABEB4B2C0

View File

@ -23,9 +23,9 @@
require('../common');
const assert = require('assert');
const http = require('http');
const Countdown = require('../common/countdown');
let nresponses = 0;
const countdown = new Countdown(2, () => server.close());
const server = http.createServer(function(req, res) {
if (req.url === '/one') {
res.writeHead(200, [['set-cookie', 'A'],
@ -55,9 +55,7 @@ server.on('listening', function() {
});
res.on('end', function() {
if (++nresponses === 2) {
server.close();
}
countdown.dec();
});
});
@ -72,14 +70,8 @@ server.on('listening', function() {
});
res.on('end', function() {
if (++nresponses === 2) {
server.close();
}
countdown.dec();
});
});
});
process.on('exit', function() {
assert.strictEqual(2, nresponses);
});