Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: http2 client ping errors #18849

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please always use a capital letter as first letter in a comment and punctuate the comments as well.

{
[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