node/test/parallel/test-http-agent-timeout-option.js
Luigi Pinca b8d9d4ac68 test: refactor test-http-agent-timeout-option
There is no need to establish a TCP connection. It is sufficient to
test that the listener that forwards the `'timeout'` event from the
socket to the `ClientRequest` instance is added to the socket.

PR-URL: https://github.com/nodejs/node/pull/25886
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2019-02-07 07:38:48 +01:00

24 lines
633 B
JavaScript

'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);
}));