summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTrivikram <16024985+trivikr@users.noreply.github.com>2018-02-17 23:15:56 -0800
committerMyles Borins <mylesborins@google.com>2018-08-16 01:59:13 -0400
commita8ae04d528c09bd895214bdf4fbff05ae9c501d7 (patch)
tree00d3787b5d16a7e7a0f6e5dba23f945dad48659e /test
parent901f5799f34858da5efe75743440d949853040c7 (diff)
downloadnode-new-a8ae04d528c09bd895214bdf4fbff05ae9c501d7.tar.gz
test: http2 client ping errors
PR-URL: https://github.com/nodejs/node/pull/18849 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-http2-ping.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/parallel/test-http2-ping.js b/test/parallel/test-http2-ping.js
index 32fb8926e4..b49e414c44 100644
--- a/test/parallel/test-http2-ping.js
+++ b/test/parallel/test-http2-ping.js
@@ -71,12 +71,60 @@ server.listen(0, common.mustCall(() => {
assert.deepStrictEqual(payload, ret);
})));
}
+
// Only max 2 pings at a time based on the maxOutstandingPings option
assert(!client.ping(common.expectsError({
code: 'ERR_HTTP2_PING_CANCEL',
type: Error,
message: 'HTTP2 ping cancelled'
})));
+
+ // should throw if payload is not of type ArrayBufferView
+ {
+ [1, true, {}, []].forEach((invalidPayload) =>
+ common.expectsError(
+ () => client.ping(invalidPayload),
+ {
+ type: TypeError,
+ code: 'ERR_INVALID_ARG_TYPE',
+ message: 'The "payload" argument must be one of type' +
+ ' Buffer, TypedArray, or DataView'
+ }
+ )
+ );
+ }
+
+ // should throw if payload length is not 8
+ {
+ const shortPayload = Buffer.from('abcdefg');
+ const longPayload = Buffer.from('abcdefghi');
+ [shortPayload, longPayload].forEach((payloadWithInvalidLength) =>
+ common.expectsError(
+ () => client.ping(payloadWithInvalidLength),
+ {
+ type: RangeError,
+ code: 'ERR_HTTP2_PING_LENGTH',
+ message: 'HTTP2 ping payload must be 8 bytes'
+ }
+ )
+ );
+ }
+
+ // should throw error is callback is not of type function
+ {
+ const payload = Buffer.from('abcdefgh');
+ [1, true, {}, []].forEach((invalidCallback) =>
+ common.expectsError(
+ () => client.ping(payload, invalidCallback),
+ {
+ type: TypeError,
+ code: 'ERR_INVALID_CALLBACK',
+ message: 'callback must be a function'
+ }
+ )
+ );
+ }
+
const req = client.request();
req.resume();
req.on('end', common.mustCall(() => {