summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLuigi Pinca <luigipinca@gmail.com>2019-02-02 08:10:28 +0100
committerLuigi Pinca <luigipinca@gmail.com>2019-02-07 07:38:48 +0100
commitb8d9d4ac68be5b95747a77b7f8bbdd62db379931 (patch)
tree5174e9935480484dcde4523ff3f06b505cbc1073 /test
parent0e54a0a2134b5aab9c24cba215ef5cfa0fcf14c3 (diff)
downloadandroid-node-v8-b8d9d4ac68be5b95747a77b7f8bbdd62db379931.tar.gz
android-node-v8-b8d9d4ac68be5b95747a77b7f8bbdd62db379931.tar.bz2
android-node-v8-b8d9d4ac68be5b95747a77b7f8bbdd62db379931.zip
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>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-http-agent-timeout-option.js38
1 files changed, 16 insertions, 22 deletions
diff --git a/test/parallel/test-http-agent-timeout-option.js b/test/parallel/test-http-agent-timeout-option.js
index 3c694a0ef7..d0c05827f2 100644
--- a/test/parallel/test-http-agent-timeout-option.js
+++ b/test/parallel/test-http-agent-timeout-option.js
@@ -1,29 +1,23 @@
'use strict';
-const { expectsError, mustCall } = require('../common');
-const { Agent, get, createServer } = require('http');
+const { mustCall } = require('../common');
+const { strictEqual } = require('assert');
+const { Agent, get } = require('http');
-// Test that the `'timeout'` event is emitted on the `ClientRequest` instance
-// when the socket timeout set via the `timeout` option of the `Agent` expires.
+// 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 server = createServer(mustCall(() => {
- // Never respond.
-}));
+const request = get({
+ agent: new Agent({ timeout: 50 }),
+ lookup: () => {}
+});
-server.listen(() => {
- const request = get({
- agent: new Agent({ timeout: 500 }),
- port: server.address().port
- });
+request.on('socket', mustCall((socket) => {
+ strictEqual(socket.timeout, 50);
- request.on('error', expectsError({
- type: Error,
- code: 'ECONNRESET',
- message: 'socket hang up'
- }));
+ const listeners = socket.listeners('timeout');
- request.on('timeout', mustCall(() => {
- request.abort();
- server.close();
- }));
-});
+ strictEqual(listeners.length, 1);
+ strictEqual(listeners[0], request.timeoutCb);
+}));