summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-server-settimeout-no-callback.js
blob: 5dff0fa8e7a93b4d39f54da1494921547d4073c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';

const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');

const assert = require('assert');
const http2 = require('http2');
const { inspect } = require('util');

// Verify that setTimeout callback verifications work correctly
const verifyCallbacks = (server) => {
  const testTimeout = 10;

  [true, 1, {}, [], null, 'test'].forEach((notFunction) => {
    common.expectsError(
      () => server.setTimeout(testTimeout, notFunction),
      {
        type: TypeError,
        code: 'ERR_INVALID_CALLBACK',
        message: 'Callback must be a function. ' +
                 `Received ${inspect(notFunction)}`
      }
    );
  });

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

// Test with server
{
  const server = http2.createServer();
  verifyCallbacks(server);
}

// Test with secure server
{
  const secureServer = http2.createSecureServer({});
  verifyCallbacks(secureServer);
}