Skip to content

Commit 53eb584

Browse files
committed
test: fix flaky http2 tests
1 parent 430c03a commit 53eb584

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

test/parallel/test-http2-pipe.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ const server = http2.createServer();
2121
server.on('stream', common.mustCall((stream) => {
2222
const dest = stream.pipe(fs.createWriteStream(fn));
2323

24-
// we might get an ECONNRESET here
25-
// or not
26-
stream.on('error', () => {});
27-
2824
dest.on('finish', () => {
2925
assert.strictEqual(fs.readFileSync(loc).length,
3026
fs.readFileSync(fn).length);
@@ -38,10 +34,6 @@ server.listen(0, common.mustCall(() => {
3834

3935
const req = client.request({ ':method': 'POST' });
4036

41-
// we might get an ECONNRESET here
42-
// or not
43-
req.on('error', () => {});
44-
4537
req.on('response', common.mustCall());
4638
req.resume();
4739

test/parallel/test-http2-server-close-callback.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ const server = http2.createServer();
1010

1111
server.listen(0, common.mustCall(() => {
1212
const client = http2.connect(`http://localhost:${server.address().port}`);
13-
14-
// depending on network events, this might or might not be emitted
15-
client.on('error', () => {});
16-
17-
client.on('connect', common.mustCall(() => {
18-
server.close(common.mustCall());
19-
}));
13+
client.on('error', (err) => {
14+
if (err.code !== 'ECONNRESET')
15+
throw err;
16+
});
2017
}));
2118

2219
server.on('session', common.mustCall((s) => {
2320
setImmediate(() => {
21+
server.close(common.mustCall());
2422
s.destroy();
2523
});
2624
}));

test/parallel/test-http2-server-stream-session-destroy.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ server.on('stream', common.mustCall((stream) => {
4444

4545
server.listen(0, common.mustCall(() => {
4646
const client = h2.connect(`http://localhost:${server.address().port}`);
47-
client.on('error', () => {});
47+
client.on('error', (err) => {
48+
if (err.code !== 'ECONNRESET')
49+
throw err;
50+
});
4851
const req = client.request();
4952
req.resume();
5053
req.on('end', common.mustCall());
51-
req.on('close', common.mustCall(() => server.close()));
52-
req.on('error', () => {});
54+
req.on('close', common.mustCall(() => server.close(common.mustCall())));
55+
req.on('error', (err) => {
56+
if (err.code !== 'ECONNRESET')
57+
throw err;
58+
});
5359
}));

test/sequential/test-http2-max-session-memory.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const largeBuffer = Buffer.alloc(1e6);
1313
const server = http2.createServer({ maxSessionMemory: 1 });
1414

1515
server.on('stream', common.mustCall((stream) => {
16-
stream.on('error', common.expectsError({
17-
code: 'ECONNRESET',
18-
type: Error
19-
}));
16+
stream.on('error', (err) => {
17+
if (err.code !== 'ECONNRESET')
18+
throw err;
19+
});
2020
stream.respond();
2121
stream.end(largeBuffer);
2222
}));

0 commit comments

Comments
 (0)