Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use countdown in http-agent test #17537

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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