GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: mock the lookup function in parallel tests · nodejs/node@da16227

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-net-better-error-messages-port-hostname.js
    • test-net-connect-immediate-finish.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-net-better-error-messages-port-hostname.js‎

Copy file name to clipboard
+18-9Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
'use strict';
2+
3+
// This tests that the error thrown from net.createConnection
4+
// comes with host and port properties.
5+
// See https://github.com/nodejs/node-v0.x-archive/issues/7005
6+
27
const common = require('../common');
38
const net = require('net');
49
const assert = require('assert');
510

11+
const { addresses } = require('../common/internet');
12+
const {
13+
errorLookupMock,
14+
mockedErrorCode
15+
} = require('../common/dns');
16+
617
// Using port 0 as hostname used is already invalid.
7-
const c = net.createConnection(0, 'this.hostname.is.invalid');
18+
const c = net.createConnection({
19+
port: 0,
20+
host: addresses.INVALID_HOST,
21+
lookup: common.mustCall(errorLookupMock())
22+
});
823

924
c.on('connect', common.mustNotCall());
1025

1126
c.on('error', common.mustCall(function(e) {
12-
// If Name Service Switch is available on the operating system then it
13-
// might be configured differently (/etc/nsswitch.conf).
14-
// If the system is configured with no dns the error code will be EAI_AGAIN,
15-
// but if there are more services after the dns entry, for example some
16-
// linux distributions ship a myhostname service by default which would
17-
// still produce the ENOTFOUND error.
18-
assert.ok(e.code === 'ENOTFOUND' || e.code === 'EAI_AGAIN');
27+
assert.strictEqual(e.code, mockedErrorCode);
1928
assert.strictEqual(e.port, 0);
20-
assert.strictEqual(e.hostname, 'this.hostname.is.invalid');
29+
assert.strictEqual(e.hostname, addresses.INVALID_HOST);
2130
}));
Collapse file

‎test/parallel/test-net-connect-immediate-finish.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-net-connect-immediate-finish.js
+18-11Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,35 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23+
24+
// This tests that if the socket is still in the 'connecting' state
25+
// when the user calls socket.end() ('finish'), the socket would emit
26+
// 'connect' and defer the handling until the 'connect' event is handled.
27+
2328
const common = require('../common');
2429
const assert = require('assert');
2530
const net = require('net');
2631

32+
const { addresses } = require('../common/internet');
33+
const {
34+
errorLookupMock,
35+
mockedErrorCode,
36+
mockedSysCall
37+
} = require('../common/dns');
38+
2739
const client = net.connect({
28-
host: 'this.hostname.is.invalid',
29-
port: common.PORT
40+
host: addresses.INVALID_HOST,
41+
port: common.PORT,
42+
lookup: common.mustCall(errorLookupMock())
3043
});
3144

3245
client.once('error', common.mustCall((err) => {
3346
assert(err);
3447
assert.strictEqual(err.code, err.errno);
35-
// If Name Service Switch is available on the operating system then it
36-
// might be configured differently (/etc/nsswitch.conf).
37-
// If the system is configured with no dns the error code will be EAI_AGAIN,
38-
// but if there are more services after the dns entry, for example some
39-
// linux distributions ship a myhostname service by default which would
40-
// still produce the ENOTFOUND error.
41-
assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN');
48+
assert.strictEqual(err.code, mockedErrorCode);
4249
assert.strictEqual(err.host, err.hostname);
43-
assert.strictEqual(err.host, 'this.hostname.is.invalid');
44-
assert.strictEqual(err.syscall, 'getaddrinfo');
50+
assert.strictEqual(err.host, addresses.INVALID_HOST);
51+
assert.strictEqual(err.syscall, mockedSysCall);
4552
}));
4653

4754
client.end();

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.