Skip to content

Commit

Permalink
test: use Countdown in http-agent test
Browse files Browse the repository at this point in the history
PR-URL: #17537
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
  • Loading branch information
fedekau authored and MylesBorins committed Dec 12, 2017
1 parent dcb53c1 commit bb780d2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions test/parallel/test-http-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit bb780d2

Please sign in to comment.