diff options
author | Luigi Pinca <luigipinca@gmail.com> | 2019-01-31 19:46:18 +0100 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-02-01 22:44:33 -0800 |
commit | 988482e2341ba31996c4a44432fd9f4f35b89dbb (patch) | |
tree | d02a03413ac3e5364ce80e9d1cd31d48bb3e24b1 /test | |
parent | 0f8e8f7c6b9e7a8bdae53c831f37b2034d1c9fa7 (diff) | |
download | android-node-v8-988482e2341ba31996c4a44432fd9f4f35b89dbb.tar.gz android-node-v8-988482e2341ba31996c4a44432fd9f4f35b89dbb.tar.bz2 android-node-v8-988482e2341ba31996c4a44432fd9f4f35b89dbb.zip |
test: refactor test-http-agent-timeout-option
Fix flakyness caused by usage of a non-routable IP address.
Refs: https://github.com/nodejs/node/pull/25488#issuecomment-459385146
PR-URL: https://github.com/nodejs/node/pull/25854
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-http-agent-timeout-option.js | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/test/parallel/test-http-agent-timeout-option.js b/test/parallel/test-http-agent-timeout-option.js index 4fcfc1f1da..3c694a0ef7 100644 --- a/test/parallel/test-http-agent-timeout-option.js +++ b/test/parallel/test-http-agent-timeout-option.js @@ -1,23 +1,29 @@ 'use strict'; const { expectsError, mustCall } = require('../common'); -const { Agent, get } = require('http'); +const { Agent, get, createServer } = 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. -const request = get({ - agent: new Agent({ timeout: 500 }), - // Non-routable IP address to prevent the connection from being established. - host: '192.0.2.1' -}); - -request.on('error', expectsError({ - type: Error, - code: 'ECONNRESET', - message: 'socket hang up' +const server = createServer(mustCall(() => { + // Never respond. })); -request.on('timeout', mustCall(() => { - request.abort(); -})); +server.listen(() => { + const request = get({ + agent: new Agent({ timeout: 500 }), + port: server.address().port + }); + + request.on('error', expectsError({ + type: Error, + code: 'ECONNRESET', + message: 'socket hang up' + })); + + request.on('timeout', mustCall(() => { + request.abort(); + server.close(); + })); +}); |