Skip to content

Commit

Permalink
test: fix flaky test-http2-client-upload
Browse files Browse the repository at this point in the history
Wait for close event on server stream before shuting down server and
client to avoid races seen on windows CI.

Refs: #20750 (comment)

PR-URL: #29889
Refs: #29852
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Flarna authored and BridgeAR committed Jan 3, 2020
1 parent 33c5dbe commit 54c471a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions test/parallel/test-http2-client-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,29 @@ fs.readFile(loc, common.mustCall((err, data) => {
fileData = data;

const server = http2.createServer();
let client;

const countdown = new Countdown(3, () => {
server.close();
client.close();
});

server.on('stream', common.mustCall((stream) => {
let data = Buffer.alloc(0);
stream.on('data', (chunk) => data = Buffer.concat([data, chunk]));
stream.on('end', common.mustCall(() => {
assert.deepStrictEqual(data, fileData);
}));
// Waiting on close avoids spurious ECONNRESET seen in windows CI.
// Not sure if this is actually a bug; more details at
// https://github.com/nodejs/node/issues/20750#issuecomment-511015247
stream.on('close', () => countdown.dec());
stream.respond();
stream.end();
}));

server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);

const countdown = new Countdown(2, () => {
server.close();
client.close();
});
client = http2.connect(`http://localhost:${server.address().port}`);

const req = client.request({ ':method': 'POST' });
req.on('response', common.mustCall());
Expand Down

0 comments on commit 54c471a

Please sign in to comment.