Skip to content

Commit 2a2fe8a

Browse files
Flarnatargos
authored andcommitted
test: fix flaky test-http2-client-upload
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 <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3c63af2 commit 2a2fe8a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,29 @@ fs.readFile(loc, common.mustCall((err, data) => {
2121
fileData = data;
2222

2323
const server = http2.createServer();
24+
let client;
25+
26+
const countdown = new Countdown(3, () => {
27+
server.close();
28+
client.close();
29+
});
2430

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

3545
server.listen(0, common.mustCall(() => {
36-
const client = http2.connect(`http://localhost:${server.address().port}`);
37-
38-
const countdown = new Countdown(2, () => {
39-
server.close();
40-
client.close();
41-
});
46+
client = http2.connect(`http://localhost:${server.address().port}`);
4247

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

0 commit comments

Comments
 (0)