Skip to content

Commit 7c484af

Browse files
committed
test: http2 add timeout no callback test case
Refs: #14985
1 parent 037d908 commit 7c484af

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

test/parallel/test-http2-server-settimeout-no-callback.js

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,39 @@ const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
66

7+
const assert = require('assert');
78
const http2 = require('http2');
89

910
// Verify that setTimeout callback verifications work correctly
11+
const verifyCallbacks = (server) => {
12+
const testTimeout = 10;
13+
const notFunctions = [true, 1, {}, [], null, 'test'];
14+
const invalidCallBackError = {
15+
type: TypeError,
16+
code: 'ERR_INVALID_CALLBACK',
17+
message: 'Callback must be a function'
18+
};
1019

20+
notFunctions.forEach((notFunction) =>
21+
common.expectsError(
22+
() => server.setTimeout(testTimeout, notFunction),
23+
invalidCallBackError
24+
)
25+
);
26+
27+
// No callback
28+
const returnedVal = server.setTimeout(testTimeout);
29+
assert.strictEqual(returnedVal.timeout, testTimeout);
30+
};
31+
32+
// Test with server
1133
{
1234
const server = http2.createServer();
13-
common.expectsError(
14-
() => server.setTimeout(10, 'test'),
15-
{
16-
code: 'ERR_INVALID_CALLBACK',
17-
type: TypeError
18-
});
19-
common.expectsError(
20-
() => server.setTimeout(10, 1),
21-
{
22-
code: 'ERR_INVALID_CALLBACK',
23-
type: TypeError
24-
});
35+
verifyCallbacks(server);
2536
}
2637

38+
// Test with secure server
2739
{
28-
const server = http2.createSecureServer({});
29-
common.expectsError(
30-
() => server.setTimeout(10, 'test'),
31-
{
32-
code: 'ERR_INVALID_CALLBACK',
33-
type: TypeError
34-
});
35-
common.expectsError(
36-
() => server.setTimeout(10, 1),
37-
{
38-
code: 'ERR_INVALID_CALLBACK',
39-
type: TypeError
40-
});
40+
const secureServer = http2.createSecureServer({});
41+
verifyCallbacks(secureServer);
4142
}

0 commit comments

Comments
 (0)