mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
test: use Countdown in http-agent test
PR-URL: https://github.com/nodejs/node/pull/17537 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
This commit is contained in:
committed by
Gibson Fahnestock
parent
5b04621c40
commit
bbb503f90b
@@ -21,6 +21,7 @@
|
||||
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const Countdown = require('../common/countdown');
|
||||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
common.crashOnUnhandledRejection();
|
||||
@@ -33,14 +34,17 @@ const server = http.Server(common.mustCall(function(req, res) {
|
||||
}, (N * M))); // N * M = good requests (the errors will not be counted)
|
||||
|
||||
function makeRequests(outCount, inCount, shouldFail) {
|
||||
let responseCount = outCount * inCount;
|
||||
const countdown = new Countdown(
|
||||
outCount * inCount,
|
||||
common.mustCall(() => server.close())
|
||||
);
|
||||
let onRequest = common.mustNotCall(); // Temporary
|
||||
const p = new Promise((resolve) => {
|
||||
onRequest = common.mustCall((res) => {
|
||||
if (--responseCount === 0) {
|
||||
server.close();
|
||||
if (countdown.dec() === 0) {
|
||||
resolve();
|
||||
}
|
||||
|
||||
if (!shouldFail)
|
||||
res.resume();
|
||||
}, outCount * inCount);
|
||||
|
||||
Reference in New Issue
Block a user