node/test/parallel/test-http-agent-timeout-option.js
Antoine du Hamel 42187494d3
test: ensure assertions are reached on HTTP tests
PR-URL: https://github.com/nodejs/node/pull/60729
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2025-11-17 20:12:12 +00:00

23 lines
645 B
JavaScript

'use strict';
const { mustCall } = require('../common');
const assert = 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) => {
assert.strictEqual(socket.timeout, 50);
const listeners = socket.listeners('timeout');
assert.strictEqual(listeners.length, 2);
assert.strictEqual(listeners[1], request.timeoutCb);
}));