Skip to content

Commit

Permalink
test: use countdown in test file
Browse files Browse the repository at this point in the history
Fixes: #17169

PR-URL: #17874
Fixes: #17169
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
sreepurnajasti authored and gibfahn committed Jan 24, 2018
1 parent 38f56cb commit f273c29
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions test/parallel/test-http-get-pipeline-problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const fixtures = require('../common/fixtures');
const assert = require('assert');
const http = require('http');
const fs = require('fs');
const Countdown = require('../common/countdown');

http.globalAgent.maxSockets = 1;

Expand All @@ -38,14 +39,12 @@ const image = fixtures.readSync('/person.jpg');
console.log(`image.length = ${image.length}`);

const total = 10;
let requests = 0;
let responses = 0;
const responseCountdown = new Countdown(total, common.mustCall(() => {
checkFiles();
server.close();
}));

const server = http.Server(function(req, res) {
if (++requests === total) {
server.close();
}

setTimeout(function() {
res.writeHead(200, {
'content-type': 'image/jpeg',
Expand Down Expand Up @@ -74,9 +73,7 @@ server.listen(0, function() {

s.on('finish', function() {
console.error(`done ${x}`);
if (++responses === total) {
checkFiles();
}
responseCountdown.dec();
});
}).on('error', function(e) {
console.error('error! ', e.message);
Expand All @@ -86,8 +83,6 @@ server.listen(0, function() {
}
});


let checkedFiles = false;
function checkFiles() {
// Should see 1.jpg, 2.jpg, ..., 100.jpg in tmpDir
const files = fs.readdirSync(common.tmpDir);
Expand All @@ -101,13 +96,4 @@ function checkFiles() {
image.length, stat.size,
`size doesn't match on '${fn}'. Got ${stat.size} bytes`);
}

checkedFiles = true;
}


process.on('exit', function() {
assert.strictEqual(total, requests);
assert.strictEqual(total, responses);
assert.ok(checkedFiles);
});

0 comments on commit f273c29

Please sign in to comment.