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>
This commit is contained in:
parent
df0334669e
commit
09b0b1bd48
18
test/parallel/test-http2-client-upload.js
Normal file → Executable file
18
test/parallel/test-http2-client-upload.js
Normal file → Executable file
@ -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…
x
Reference in New Issue
Block a user