Skip to content

Commit 9d752d5

Browse files
jasnelladdaleax
authored andcommitted
test: fix flakiness in test-http2-client-upload
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]>
1 parent be716d0 commit 9d752d5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

100644100755
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,21 @@ fs.readFile(loc, common.mustCall((err, data) => {
3232

3333
server.listen(0, common.mustCall(() => {
3434
const client = http2.connect(`http://localhost:${server.address().port}`);
35+
36+
let remaining = 2;
37+
function maybeClose() {
38+
if (--remaining === 0) {
39+
server.close();
40+
client.destroy();
41+
}
42+
}
43+
3544
const req = client.request({ ':method': 'POST' });
3645
req.on('response', common.mustCall());
3746
req.resume();
38-
req.on('end', common.mustCall(() => {
39-
server.close();
40-
client.destroy();
41-
}));
42-
fs.createReadStream(loc).pipe(req);
47+
req.on('end', common.mustCall(maybeClose));
48+
const str = fs.createReadStream(loc);
49+
str.on('end', common.mustCall(maybeClose));
50+
str.pipe(req);
4351
}));
4452
}));

0 commit comments

Comments
 (0)