Skip to content

Commit 66a5f99

Browse files
ssbrewsterjasnell
authored andcommitted
http2: improved coverage of Http2Stream destroy
Refs: #14985 PR-URL: #15461 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 757c342 commit 66a5f99

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Flags: --expose-http2
2+
'use strict';
3+
4+
const common = require('../common');
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
const assert = require('assert');
8+
const http2 = require('http2');
9+
10+
const server = http2.createServer();
11+
12+
// Test that ERR_HTTP2_INVALID_STREAM is thrown when a stream is destroyed
13+
// before calling stream.priority
14+
server.on('stream', common.mustCall(onStream));
15+
16+
function onStream(stream, headers, flags) {
17+
stream.session.destroy();
18+
assert.throws(() => stream.priority(),
19+
common.expectsError({
20+
code: 'ERR_HTTP2_INVALID_STREAM',
21+
message: /^The stream has been destroyed$/
22+
}));
23+
}
24+
25+
server.listen(0);
26+
27+
server.on('listening', common.mustCall(() => {
28+
29+
const client = http2.connect(`http://localhost:${server.address().port}`);
30+
31+
const req = client.request({ ':path': '/' });
32+
33+
req.on('response', common.mustNotCall());
34+
req.resume();
35+
req.on('end', common.mustCall(() => {
36+
server.close();
37+
client.destroy();
38+
}));
39+
req.end();
40+
41+
}));
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Flags: --expose-http2
2+
'use strict';
3+
4+
const common = require('../common');
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
const assert = require('assert');
8+
const http2 = require('http2');
9+
10+
const server = http2.createServer();
11+
12+
// Test that ERR_HTTP2_INVALID_STREAM is thrown when a stream is destroyed
13+
// before calling stream.rstStream
14+
server.on('stream', common.mustCall(onStream));
15+
16+
function onStream(stream, headers, flags) {
17+
stream.session.destroy();
18+
assert.throws(() => stream.rstStream(),
19+
common.expectsError({
20+
code: 'ERR_HTTP2_INVALID_STREAM',
21+
message: /^The stream has been destroyed$/
22+
}));
23+
}
24+
25+
server.listen(0);
26+
27+
server.on('listening', common.mustCall(() => {
28+
29+
const client = http2.connect(`http://localhost:${server.address().port}`);
30+
31+
const req = client.request({ ':path': '/' });
32+
33+
req.on('response', common.mustNotCall());
34+
req.resume();
35+
req.on('end', common.mustCall(() => {
36+
server.close();
37+
client.destroy();
38+
}));
39+
req.end();
40+
41+
}));
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Flags: --expose-http2
2+
'use strict';
3+
4+
const common = require('../common');
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
const assert = require('assert');
8+
const http2 = require('http2');
9+
10+
const server = http2.createServer();
11+
12+
// Test that stream.state getter returns and empty object
13+
// if the stream session has been destroyed
14+
server.on('stream', common.mustCall(onStream));
15+
16+
function onStream(stream, headers, flags) {
17+
stream.session.destroy();
18+
assert.deepStrictEqual(Object.create(null), stream.state);
19+
}
20+
21+
server.listen(0);
22+
23+
server.on('listening', common.mustCall(() => {
24+
25+
const client = http2.connect(`http://localhost:${server.address().port}`);
26+
27+
const req = client.request({ ':path': '/' });
28+
29+
req.on('response', common.mustNotCall());
30+
req.resume();
31+
req.on('end', common.mustCall(() => {
32+
server.close();
33+
client.destroy();
34+
}));
35+
req.end();
36+
37+
}));

0 commit comments

Comments
 (0)