• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const http = require('http');
5
6assert.throws(() => {
7  http.request({ timeout: null });
8}, /The "timeout" argument must be of type number/);
9
10const options = {
11  method: 'GET',
12  port: undefined,
13  host: '127.0.0.1',
14  path: '/',
15  timeout: 1
16};
17
18const server = http.createServer();
19
20server.listen(0, options.host, function() {
21  options.port = this.address().port;
22  const req = http.request(options);
23  req.on('error', function() {
24    // This space is intentionally left blank
25  });
26  req.on('close', common.mustCall(() => server.close()));
27
28  let timeout_events = 0;
29  req.on('timeout', common.mustCall(() => timeout_events += 1));
30  setTimeout(function() {
31    req.destroy();
32    assert.strictEqual(timeout_events, 1);
33  }, common.platformTimeout(100));
34  setTimeout(function() {
35    req.end();
36  }, common.platformTimeout(10));
37});
38