Skip to content

Commit

Permalink
test: use Countdown in http test
Browse files Browse the repository at this point in the history
PR-URL: #17436
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Jon Moss <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
mithunsasidharan authored and MylesBorins committed Dec 12, 2017
1 parent 8c81ba0 commit 85e6271
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions test/parallel/test-http-response-multi-content-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const common = require('../common');
const http = require('http');
const assert = require('assert');
const Countdown = require('../common/countdown');

const MAX_COUNT = 2;

Expand All @@ -24,7 +25,7 @@ const server = http.createServer((req, res) => {
res.end('ok');
});

let count = 0;
const countdown = new Countdown(MAX_COUNT, () => server.close());

server.listen(0, common.mustCall(() => {
for (let n = 1; n <= MAX_COUNT; n++) {
Expand All @@ -40,13 +41,7 @@ server.listen(0, common.mustCall(() => {
).on('error', common.mustCall((err) => {
assert(/^Parse Error/.test(err.message));
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
count++;
if (count === MAX_COUNT)
server.close();
countdown.dec();
}));
}
}));

process.on('exit', () => {
assert.strictEqual(count, MAX_COUNT);
});

0 comments on commit 85e6271

Please sign in to comment.