-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
7144544
commit 28a96ab
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