test: use Countdown in http-response-statuscode
PR-URL: https://github.com/nodejs/node/pull/17327 Refs: https://github.com/nodejs/node/issues/17169 Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
This commit is contained in:
parent
6a089f9357
commit
f3f66a8d5a
@ -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;
|
||||
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user