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: Update test-http-parser-free to use countdown timer #17322

Closed
wants to merge 3 commits into from
Closed
Changes from 2 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: 5 additions & 5 deletions test/parallel/test-http-parser-free.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
require('../common');
const assert = require('assert');
const http = require('http');
const Countdown = require('../common/countdown');
const N = 100;
let responses = 0;

const server = http.createServer(function(req, res) {
res.end('Hello');
});

const countdown = new Countdown(N, () => server.close());

server.listen(0, function() {
http.globalAgent.maxSockets = 1;
let parser;
Expand All @@ -42,15 +44,13 @@ server.listen(0, function() {
assert.strictEqual(req.parser, parser);
}

if (++responses === N) {
server.close();
}
countdown.dec();
res.resume();
});
})(i);
}
});

process.on('exit', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this check? Doesn't server.close() / end of execution from the Countdown mean we've already hit zero remaining?

cc @jasnell

Copy link
Member

Choose a reason for hiding this comment

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

Yep, the process.on('exit') can be removed.

assert.strictEqual(responses, N);
assert.strictEqual(0, countdown.remaining);
});