-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #17296 Refs: nodejs/help#687 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
4e789a3
commit 3d45a94
Showing
3 changed files
with
49 additions
and
23 deletions.
There are no files selected for viewing
16 changes: 13 additions & 3 deletions
16
test/parallel/test-http-client-req-error-dont-double-fire.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 18 additions & 9 deletions
27
test/parallel/test-net-better-error-messages-port-hostname.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
'use strict'; | ||
|
||
// This tests that the error thrown from net.createConnection | ||
// comes with host and port properties. | ||
// See https://github.com/nodejs/node-v0.x-archive/issues/7005 | ||
|
||
const common = require('../common'); | ||
const net = require('net'); | ||
const assert = require('assert'); | ||
|
||
const { addresses } = require('../common/internet'); | ||
const { | ||
errorLookupMock, | ||
mockedErrorCode | ||
} = require('../common/dns'); | ||
|
||
// Using port 0 as hostname used is already invalid. | ||
const c = net.createConnection(0, 'this.hostname.is.invalid'); | ||
const c = net.createConnection({ | ||
port: 0, | ||
host: addresses.INVALID_HOST, | ||
lookup: common.mustCall(errorLookupMock()) | ||
}); | ||
|
||
c.on('connect', common.mustNotCall()); | ||
|
||
c.on('error', common.mustCall(function(e) { | ||
// 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(e.code === 'ENOTFOUND' || e.code === 'EAI_AGAIN'); | ||
assert.strictEqual(e.code, mockedErrorCode); | ||
assert.strictEqual(e.port, 0); | ||
assert.strictEqual(e.hostname, 'this.hostname.is.invalid'); | ||
assert.strictEqual(e.hostname, addresses.INVALID_HOST); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters