Skip to content

Commit 747d9ae

Browse files
lpincatargos
authored andcommittedOct 2, 2024
test: deflake test-http2-misbehaving-multiplex
Fixes: #54859 PR-URL: #54872 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed
 

Diff for: ‎test/parallel/test-http2-misbehaving-multiplex.js

+21-18
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,30 @@ const h2 = require('http2');
1111
const net = require('net');
1212
const { NghttpError } = require('internal/http2/util');
1313
const h2test = require('../common/http2');
14+
let client;
1415

1516
const server = h2.createServer();
1617
server.on('stream', common.mustCall((stream) => {
1718
stream.respond();
18-
stream.end('ok');
1919

20-
stream.on('error', common.expectsError({
21-
code: 'ERR_HTTP2_ERROR',
22-
constructor: NghttpError,
23-
message: 'Stream was already closed or invalid'
24-
}));
25-
stream.on('close', common.mustCall());
20+
if (stream.id === 3) {
21+
stream.on('close', () => {
22+
// A second Stream ID 1 frame should fail.
23+
// This will cause an error to occur because the client is
24+
// attempting to reuse an already closed stream. This must
25+
// cause the server session to be torn down.
26+
client.write(id1.data);
27+
// This Stream ID 5 frame will never make it to the server.
28+
client.write(id5.data);
29+
});
30+
stream.end('ok');
31+
} else {
32+
stream.on('error', common.expectsError({
33+
code: 'ERR_HTTP2_ERROR',
34+
constructor: NghttpError,
35+
message: 'Stream was already closed or invalid'
36+
}));
37+
}
2638

2739
// Stream ID 5 should never reach the server
2840
assert.notStrictEqual(stream.id, 5);
@@ -45,23 +57,14 @@ const id3 = new h2test.HeadersFrame(3, h2test.kFakeRequestHeaders, 0, true);
4557
const id5 = new h2test.HeadersFrame(5, h2test.kFakeRequestHeaders, 0, true);
4658

4759
server.listen(0, () => {
48-
const client = net.connect(server.address().port, () => {
60+
client = net.connect(server.address().port, () => {
4961
client.write(h2test.kClientMagic, () => {
5062
client.write(settings.data, () => {
5163
client.write(settingsAck.data);
5264
// Stream ID 1 frame will make it OK.
5365
client.write(id1.data, () => {
5466
// Stream ID 3 frame will make it OK.
55-
client.write(id3.data, () => {
56-
// A second Stream ID 1 frame should fail.
57-
// This will cause an error to occur because the client is
58-
// attempting to reuse an already closed stream. This must
59-
// cause the server session to be torn down.
60-
client.write(id1.data, () => {
61-
// This Stream ID 5 frame will never make it to the server
62-
client.write(id5.data);
63-
});
64-
});
67+
client.write(id3.data);
6568
});
6669
});
6770
});

0 commit comments

Comments
 (0)
Please sign in to comment.