Browse Source

test: fix flakiness in test-http2-client-upload

Race condition in the closing of the stream causing failure on
some platforms.

PR-URL: https://github.com/nodejs/node/pull/14239
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
v6
James M Snell 7 years ago
parent
commit
09b0b1bd48
  1. 18
      test/parallel/test-http2-client-upload.js

18
test/parallel/test-http2-client-upload.js

@ -32,13 +32,21 @@ fs.readFile(loc, common.mustCall((err, data) => {
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
let remaining = 2;
function maybeClose() {
if (--remaining === 0) {
server.close();
client.destroy();
}
}
const req = client.request({ ':method': 'POST' });
req.on('response', common.mustCall());
req.resume();
req.on('end', common.mustCall(() => {
server.close();
client.destroy();
}));
fs.createReadStream(loc).pipe(req);
req.on('end', common.mustCall(maybeClose));
const str = fs.createReadStream(loc);
str.on('end', common.mustCall(maybeClose));
str.pipe(req);
}));
}));

Loading…
Cancel
Save