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 add timeout no callback test case #16082

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
51 changes: 26 additions & 25 deletions test/parallel/test-http2-server-settimeout-no-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,39 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

const assert = require('assert');
const http2 = require('http2');

// Verify that setTimeout callback verifications work correctly
const verifyCallbacks = (server) => {
const testTimeout = 10;
const notFunctions = [true, 1, {}, [], null, 'test'];
const invalidCallBackError = {
type: TypeError,
code: 'ERR_INVALID_CALLBACK',
message: 'Callback must be a function'
};

notFunctions.forEach((notFunction) =>
common.expectsError(
() => server.setTimeout(testTimeout, notFunction),
invalidCallBackError
)
);

// No callback
const returnedVal = server.setTimeout(testTimeout);
assert.strictEqual(returnedVal.timeout, testTimeout);
};

// Test with server
{
const server = http2.createServer();
common.expectsError(
() => server.setTimeout(10, 'test'),
{
code: 'ERR_INVALID_CALLBACK',
type: TypeError
});
common.expectsError(
() => server.setTimeout(10, 1),
{
code: 'ERR_INVALID_CALLBACK',
type: TypeError
});
verifyCallbacks(server);
}

// Test with secure server
{
const server = http2.createSecureServer({});
common.expectsError(
() => server.setTimeout(10, 'test'),
{
code: 'ERR_INVALID_CALLBACK',
type: TypeError
});
common.expectsError(
() => server.setTimeout(10, 1),
{
code: 'ERR_INVALID_CALLBACK',
type: TypeError
});
const secureServer = http2.createSecureServer({});
verifyCallbacks(secureServer);
}