1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6const assert = require('assert');
7const h2 = require('http2');
8
9const server = h2.createServer();
10
11// We use the lower-level API here
12server.on('stream', common.mustCall((stream) => {
13  stream.setTimeout(1, common.mustCall(() => {
14    stream.respond({ ':status': 200 });
15    stream.end('hello world');
16  }));
17
18  // Check that expected errors are thrown with wrong args
19  assert.throws(
20    () => stream.setTimeout('100'),
21    {
22      code: 'ERR_INVALID_ARG_TYPE',
23      name: 'TypeError',
24      message:
25        'The "msecs" argument must be of type number. Received type string' +
26        " ('100')"
27    }
28  );
29  assert.throws(
30    () => stream.setTimeout(0, Symbol('test')),
31    {
32      code: 'ERR_INVALID_ARG_TYPE',
33      name: 'TypeError',
34    }
35  );
36  assert.throws(
37    () => stream.setTimeout(100, {}),
38    {
39      code: 'ERR_INVALID_ARG_TYPE',
40      name: 'TypeError',
41    }
42  );
43}));
44server.listen(0);
45
46server.on('listening', common.mustCall(() => {
47  const client = h2.connect(`http://localhost:${server.address().port}`);
48  client.setTimeout(1, common.mustCall(() => {
49    const req = client.request({ ':path': '/' });
50    req.setTimeout(1, common.mustCall(() => {
51      req.on('response', common.mustCall());
52      req.resume();
53      req.on('end', common.mustCall(() => {
54        server.close();
55        client.close();
56      }));
57      req.end();
58    }));
59  }));
60}));
61