Skip to content

Commit e5cf833

Browse files
trivikrMylesBorins
authored andcommitted
test: http2 priority stream depends on itself
This commit add test case where priority() throws ERR_INVALID_OPT_VALUE when stream depends on itself Refs: #14985 PR-URL: #16224 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 50b4965 commit e5cf833

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
const h2 = require('http2');
7+
8+
const server = h2.createServer();
9+
const invalidOptValueError = (value) => ({
10+
type: TypeError,
11+
code: 'ERR_INVALID_OPT_VALUE',
12+
message: `The value "${value}" is invalid for option "parent"`
13+
});
14+
15+
// we use the lower-level API here
16+
server.on('stream', common.mustCall((stream) => {
17+
common.expectsError(
18+
() => stream.priority({
19+
parent: stream.id,
20+
weight: 1,
21+
exclusive: false
22+
}),
23+
invalidOptValueError(stream.id)
24+
);
25+
stream.respond({
26+
'content-type': 'text/html',
27+
':status': 200
28+
});
29+
stream.end('hello world');
30+
}));
31+
32+
server.listen(0, common.mustCall(() => {
33+
34+
const client = h2.connect(`http://localhost:${server.address().port}`);
35+
const req = client.request({ ':path': '/' });
36+
37+
req.on(
38+
'ready',
39+
() => common.expectsError(
40+
() => req.priority({
41+
parent: req.id,
42+
weight: 1,
43+
exclusive: false
44+
}),
45+
invalidOptValueError(req.id)
46+
)
47+
);
48+
49+
req.on('response', common.mustCall());
50+
req.resume();
51+
req.on('end', common.mustCall(() => {
52+
server.close();
53+
client.destroy();
54+
}));
55+
req.end();
56+
57+
}));

0 commit comments

Comments
 (0)