Skip to content
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
Next Next commit
test: use countdown utility
  • Loading branch information
HarshithaKP committed Mar 12, 2020
commit c6bc3042f7a2979ae95f3047160c97756c9022ec
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
Copy Markdown
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