diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2017-11-25 23:58:24 +0900 |
---|---|---|
committer | Gibson Fahnestock <gibfahn@gmail.com> | 2018-04-12 00:48:01 +0100 |
commit | da162278dea69e1372562305618834b6722c6e84 (patch) | |
tree | 958998ea1c665b865c65a48dabcaab42cef7a052 /test/parallel/test-net-connect-immediate-finish.js | |
parent | 34af49401b1779379f3e6acc33c89a4138bab2f4 (diff) | |
download | node-new-da162278dea69e1372562305618834b6722c6e84.tar.gz |
test: mock the lookup function in parallel tests
These tests should not make any DNS calls. The lookup would fail
when the DNS requests are hijacked and time out instead of erroring
out.
PR-URL: https://github.com/nodejs/node/pull/17296
Backport-PR-URL: https://github.com/nodejs/node/pull/19706
Refs: https://github.com/nodejs/help/issues/687
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-net-connect-immediate-finish.js')
-rw-r--r-- | test/parallel/test-net-connect-immediate-finish.js | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/test/parallel/test-net-connect-immediate-finish.js b/test/parallel/test-net-connect-immediate-finish.js index e2e5e1c671..9adf8c3112 100644 --- a/test/parallel/test-net-connect-immediate-finish.js +++ b/test/parallel/test-net-connect-immediate-finish.js @@ -20,28 +20,35 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; + +// This tests that if the socket is still in the 'connecting' state +// when the user calls socket.end() ('finish'), the socket would emit +// 'connect' and defer the handling until the 'connect' event is handled. + const common = require('../common'); const assert = require('assert'); const net = require('net'); +const { addresses } = require('../common/internet'); +const { + errorLookupMock, + mockedErrorCode, + mockedSysCall +} = require('../common/dns'); + const client = net.connect({ - host: 'this.hostname.is.invalid', - port: common.PORT + host: addresses.INVALID_HOST, + port: common.PORT, + lookup: common.mustCall(errorLookupMock()) }); client.once('error', common.mustCall((err) => { assert(err); assert.strictEqual(err.code, err.errno); - // If Name Service Switch is available on the operating system then it - // might be configured differently (/etc/nsswitch.conf). - // If the system is configured with no dns the error code will be EAI_AGAIN, - // but if there are more services after the dns entry, for example some - // linux distributions ship a myhostname service by default which would - // still produce the ENOTFOUND error. - assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN'); + assert.strictEqual(err.code, mockedErrorCode); assert.strictEqual(err.host, err.hostname); - assert.strictEqual(err.host, 'this.hostname.is.invalid'); - assert.strictEqual(err.syscall, 'getaddrinfo'); + assert.strictEqual(err.host, addresses.INVALID_HOST); + assert.strictEqual(err.syscall, mockedSysCall); })); client.end(); |