Skip to content

Commit

Permalink
test: fix flakiness in test-http2-client-upload
Browse files Browse the repository at this point in the history
Race condition in the closing of the stream causing failure on
some platforms.

Backport-PR-URL: #14813
Backport-Reviewed-By: Anna Henningsen <[email protected]>
Backport-Reviewed-By: Timothy Gu <[email protected]>

PR-URL: #14239
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
jasnell authored and addaleax committed Aug 14, 2017
1 parent be716d0 commit 9d752d5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions test/parallel/test-http2-client-upload.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));
}));

0 comments on commit 9d752d5

Please sign in to comment.