Skip to content

Commit

Permalink
test: deflake test-http2-misbehaving-multiplex
Browse files Browse the repository at this point in the history
Fixes: #54859
  • Loading branch information
lpinca committed Sep 10, 2024
1 parent 741004a commit c2546eb
Showing 1 changed file with 19 additions and 33 deletions.
52 changes: 19 additions & 33 deletions test/parallel/test-http2-misbehaving-multiplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,27 @@ const h2test = require('../common/http2');
let client;

const server = h2.createServer();
let gotFirstStreamId1;
server.on('stream', common.mustCall((stream) => {
stream.respond();
stream.end('ok');

// Http2Server should be fast enough to respond to and close
// the first streams with ID 1 and ID 3 without errors.

// Test for errors in 'close' event to ensure no errors on some streams.
stream.on('error', () => {});
stream.on('close', (err) => {
if (stream.id === 1) {
if (gotFirstStreamId1) {
// We expect our outgoing frames to fail on Stream ID 1 the second time
// because a stream with ID 1 was already closed before.
common.expectsError({
constructor: NghttpError,
code: 'ERR_HTTP2_ERROR',
message: 'Stream was already closed or invalid'
});
return;
}
gotFirstStreamId1 = true;
}
assert.strictEqual(err, undefined);
});
if (stream.id === 3) {
stream.on('close', () => {
// A second Stream ID 1 frame should fail.
// This will cause an error to occur because the client is
// attempting to reuse an already closed stream. This must
// cause the server session to be torn down.
client.write(id1.data);
// This Stream ID 5 frame will never make it to the server.
client.write(id5.data);
});
stream.end('ok');
} else {
stream.on('error', common.expectsError({
code: 'ERR_HTTP2_ERROR',
constructor: NghttpError,
message: 'Stream was already closed or invalid'
}));
}

// Stream ID 5 should never reach the server
assert.notStrictEqual(stream.id, 5);
Expand Down Expand Up @@ -69,16 +64,7 @@ server.listen(0, () => {
// Stream ID 1 frame will make it OK.
client.write(id1.data, () => {
// Stream ID 3 frame will make it OK.
client.write(id3.data, () => {
// A second Stream ID 1 frame should fail.
// This will cause an error to occur because the client is
// attempting to reuse an already closed stream. This must
// cause the server session to be torn down.
client.write(id1.data, () => {
// This Stream ID 5 frame will never make it to the server
client.write(id5.data);
});
});
client.write(id3.data);
});
});
});
Expand Down

0 comments on commit c2546eb

Please sign in to comment.