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(() => {
27    assert.strictEqual(req.destroyed, true);
28    server.close();
29  }));
30
31  let timeout_events = 0;
32  req.on('timeout', common.mustCall(() => timeout_events += 1));
33  setTimeout(function() {
34    req.destroy();
35    assert.strictEqual(timeout_events, 1);
36  }, common.platformTimeout(100));
37  setTimeout(function() {
38    req.end();
39  }, common.platformTimeout(10));
40});
41