Skip to content

Commit

Permalink
test: http2 client ping errors
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
trivikr authored and MylesBorins committed Aug 16, 2018
1 parent 901f579 commit a8ae04d
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/parallel/test-http2-ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit a8ae04d

Please sign in to comment.