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 utility #32224

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions test/parallel/test-https-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');

if (!common.hasCrypto)
common.skip('missing crypto');
Expand All @@ -40,11 +41,14 @@ const server = https.Server(options, function(req, res) {
res.end('hello world\n');
});


let responses = 0;
const N = 4;
const M = 4;

const cd = new Countdown(N * M, () => {
server.close();
});


server.listen(0, function() {
for (let i = 0; i < N; i++) {
Expand All @@ -57,7 +61,8 @@ server.listen(0, function() {
}, function(res) {
res.resume();
assert.strictEqual(res.statusCode, 200);
if (++responses === N * M) server.close();
++responses;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By adding the countdown you can eliminate the responses counter and the process.on('exit') check

cd.dec();
}).on('error', function(e) {
throw e;
});
Expand Down