Skip to content

Commit b7e6ac7

Browse files
trivikrMylesBorins
authored andcommitted
test: http2 client ping errors
PR-URL: #18849 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent f90490d commit b7e6ac7

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/parallel/test-http2-ping.js

+48
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,60 @@ server.listen(0, common.mustCall(() => {
7171
assert.deepStrictEqual(payload, ret);
7272
})));
7373
}
74+
7475
// Only max 2 pings at a time based on the maxOutstandingPings option
7576
assert(!client.ping(common.expectsError({
7677
code: 'ERR_HTTP2_PING_CANCEL',
7778
type: Error,
7879
message: 'HTTP2 ping cancelled'
7980
})));
81+
82+
// should throw if payload is not of type ArrayBufferView
83+
{
84+
[1, true, {}, []].forEach((invalidPayload) =>
85+
common.expectsError(
86+
() => client.ping(invalidPayload),
87+
{
88+
type: TypeError,
89+
code: 'ERR_INVALID_ARG_TYPE',
90+
message: 'The "payload" argument must be one of type' +
91+
' Buffer, TypedArray, or DataView'
92+
}
93+
)
94+
);
95+
}
96+
97+
// should throw if payload length is not 8
98+
{
99+
const shortPayload = Buffer.from('abcdefg');
100+
const longPayload = Buffer.from('abcdefghi');
101+
[shortPayload, longPayload].forEach((payloadWithInvalidLength) =>
102+
common.expectsError(
103+
() => client.ping(payloadWithInvalidLength),
104+
{
105+
type: RangeError,
106+
code: 'ERR_HTTP2_PING_LENGTH',
107+
message: 'HTTP2 ping payload must be 8 bytes'
108+
}
109+
)
110+
);
111+
}
112+
113+
// should throw error is callback is not of type function
114+
{
115+
const payload = Buffer.from('abcdefgh');
116+
[1, true, {}, []].forEach((invalidCallback) =>
117+
common.expectsError(
118+
() => client.ping(payload, invalidCallback),
119+
{
120+
type: TypeError,
121+
code: 'ERR_INVALID_CALLBACK',
122+
message: 'Callback must be a function'
123+
}
124+
)
125+
);
126+
}
127+
80128
const req = client.request();
81129
req.resume();
82130
req.on('end', common.mustCall(() => {

0 commit comments

Comments
 (0)