Skip to content

Commit

Permalink
test: use Countdown in http-response-statuscode
Browse files Browse the repository at this point in the history
PR-URL: #17327
Refs: #17169
Reviewed-By: Jon Moss <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
  • Loading branch information
daxlab authored and MylesBorins committed Dec 12, 2017
1 parent 919625b commit 2a5da9c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/parallel/test-http-response-statuscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const common = require('../common');
const assert = require('assert');
const http = require('http');
const Countdown = require('../common/countdown');

const MAX_REQUESTS = 13;
let reqNum = 0;
Expand Down Expand Up @@ -72,13 +73,17 @@ const server = http.Server(common.mustCall(function(req, res) {
}, MAX_REQUESTS));
server.listen();

const countdown = new Countdown(MAX_REQUESTS, () => server.close());

server.on('listening', function makeRequest() {
http.get({
port: this.address().port
}, (res) => {
assert.strictEqual(res.statusCode, 200);
res.on('end', () => {
if (++reqNum < MAX_REQUESTS)
countdown.dec();
reqNum = MAX_REQUESTS - countdown.remaining;
if (countdown.remaining > 0)
makeRequest.call(this);
});
res.resume();
Expand Down

0 comments on commit 2a5da9c

Please sign in to comment.