Skip to content

test: update test/parallel/test-http-pipe-fs.js to use countdown #17346

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

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
10 changes: 6 additions & 4 deletions test/parallel/test-http-pipe-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const common = require('../common');
const http = require('http');
const fs = require('fs');
const path = require('path');
const Countdown = require('../common/countdown');
const NUMBER_OF_STREAMS = 2;

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

common.refreshTmpDir();

Expand All @@ -39,7 +43,7 @@ const server = http.createServer(common.mustCall(function(req, res) {
}, 2)).listen(0, function() {
http.globalAgent.maxSockets = 1;

for (let i = 0; i < 2; ++i) {
for (let i = 0; i < NUMBER_OF_STREAMS; ++i) {
(function(i) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this entire closure might be unnecessary now, because the countdown removes the only use of i that was not for debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@addaleax I just push a new commit that removes the unnecessary IIFE.

const req = http.request({
port: server.address().port,
Expand All @@ -50,9 +54,7 @@ const server = http.createServer(common.mustCall(function(req, res) {
}, function(res) {
res.on('end', function() {
console.error(`res${i} end`);
if (i === 2) {
server.close();
}
countdown.dec();
});
res.resume();
});
Expand Down