summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-agent-timeout-option.js
blob: d0c05827f23d561010a26ce619d9a972a4547b76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'use strict';

const { mustCall } = require('../common');
const { strictEqual } = require('assert');
const { Agent, get } = require('http');

// Test that the listener that forwards the `'timeout'` event from the socket to
// the `ClientRequest` instance is added to the socket when the `timeout` option
// of the `Agent` is set.

const request = get({
  agent: new Agent({ timeout: 50 }),
  lookup: () => {}
});

request.on('socket', mustCall((socket) => {
  strictEqual(socket.timeout, 50);

  const listeners = socket.listeners('timeout');

  strictEqual(listeners.length, 1);
  strictEqual(listeners[0], request.timeoutCb);
}));