node/test/parallel/test-http-client-timeout-option-with-agent.js
Luigi Pinca b361f9577f test: refactor two http client timeout tests
Refactor test-http-client-set-timeout and
test-http-client-timeout-option-with-agent.

PR-URL: https://github.com/nodejs/node/pull/25473
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-02-12 08:01:26 +01:00

24 lines
555 B
JavaScript

'use strict';
// Test that the request `timeout` option has precedence over the agent
// `timeout` option.
const { mustCall } = require('../common');
const { Agent, get } = require('http');
const { strictEqual } = require('assert');
const request = get({
agent: new Agent({ timeout: 50 }),
lookup: () => {},
timeout: 100
});
request.on('socket', mustCall((socket) => {
strictEqual(socket.timeout, 100);
const listeners = socket.listeners('timeout');
strictEqual(listeners.length, 1);
strictEqual(listeners[0], request.timeoutCb);
}));