Skip to content

Commit 130edc7

Browse files
committed
SmartOS fixes for the test suite
Explanations: test/parallel/test-net-connect-options-port.js: add `family: 4` at various places to force `localhost` or default `localhost` to be resolved to legacy IPv4 addresses. test/parallel/test-net-pingpong.js: change `localhost` to `127.0.0.1` because test is aimed at legacy IPv4, so it can be forced to literal IPv4 address without problem. NEEDS TESTING: does `pingPongTest(0);` pass? test/parallel/test-net-remote-address-port.js: change `localhost` to `127.0.0.1` and force IPv4 by adding `family: 4` because SmartOS will resolve `localhost` or no address automatically to legacy IPv4 address (`127.0.0.1`). test/parallel/test-net-writable.js: listen on `common.localhostIPv4` and add `family: 4` to connect to force IPv4. because SmartOS will resolve `localhost` or no address automatically to legacy IPv4 address (`127.0.0.1`). test/sequential/test-https-connect-localport.js: revert previous change, i.e. readd `family: 4` to `https.get`. Change `localhost` on listen to `common.localhostIPv4` to force legacy IPv4.
1 parent 88d5f24 commit 130edc7

5 files changed

+34
-20
lines changed

test/parallel/test-net-connect-options-port.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const net = require('net');
8383
}
8484
}, expectedConnections));
8585

86-
server.listen(0, 'localhost', common.mustCall(() => {
86+
server.listen(0, common.localhostIPv4, common.mustCall(() => {
8787
const port = server.address().port;
8888

8989
// Total connections = 3 * 4(canConnect) * 6(doConnect) = 72
@@ -133,28 +133,35 @@ function doConnect(args, getCb) {
133133
}
134134

135135
function syncFailToConnect(port, assertErr, optOnly) {
136+
const family = 4;
136137
if (!optOnly) {
137138
// connect(port, cb) and connect(port)
138-
const portArgFunctions = doConnect([port], () => common.mustNotCall());
139+
const portArgFunctions = doConnect([{ port, family }],
140+
() => common.mustNotCall());
139141
for (const fn of portArgFunctions) {
140142
assert.throws(fn, assertErr, `${fn.name}(${port})`);
141143
}
142144

143145
// connect(port, host, cb) and connect(port, host)
144-
const portHostArgFunctions = doConnect([port, 'localhost'],
146+
const portHostArgFunctions = doConnect([{ port,
147+
host: 'localhost',
148+
family }],
145149
() => common.mustNotCall());
146150
for (const fn of portHostArgFunctions) {
147151
assert.throws(fn, assertErr, `${fn.name}(${port}, 'localhost')`);
148152
}
149153
}
150154
// connect({port}, cb) and connect({port})
151-
const portOptFunctions = doConnect([{ port }], () => common.mustNotCall());
155+
const portOptFunctions = doConnect([{ port, family }],
156+
() => common.mustNotCall());
152157
for (const fn of portOptFunctions) {
153158
assert.throws(fn, assertErr, `${fn.name}({port: ${port}})`);
154159
}
155160

156161
// connect({port, host}, cb) and connect({port, host})
157-
const portHostOptFunctions = doConnect([{ port: port, host: 'localhost' }],
162+
const portHostOptFunctions = doConnect([{ port: port,
163+
host: 'localhost',
164+
family }],
158165
() => common.mustNotCall());
159166
for (const fn of portHostOptFunctions) {
160167
assert.throws(fn,
@@ -165,27 +172,30 @@ function syncFailToConnect(port, assertErr, optOnly) {
165172

166173
function canConnect(port) {
167174
const noop = () => common.mustCall();
175+
const family = 4;
168176

169177
// connect(port, cb) and connect(port)
170-
const portArgFunctions = doConnect([port], noop);
178+
const portArgFunctions = doConnect([{ port, family }], noop);
171179
for (const fn of portArgFunctions) {
172180
fn();
173181
}
174182

175183
// connect(port, host, cb) and connect(port, host)
176-
const portHostArgFunctions = doConnect([port, 'localhost'], noop);
184+
const portHostArgFunctions = doConnect([{ port, host: 'localhost', family }],
185+
noop);
177186
for (const fn of portHostArgFunctions) {
178187
fn();
179188
}
180189

181190
// connect({port}, cb) and connect({port})
182-
const portOptFunctions = doConnect([{ port }], noop);
191+
const portOptFunctions = doConnect([{ port, family }], noop);
183192
for (const fn of portOptFunctions) {
184193
fn();
185194
}
186195

187196
// connect({port, host}, cb) and connect({port, host})
188-
const portHostOptFns = doConnect([{ port, host: 'localhost' }], noop);
197+
const portHostOptFns = doConnect([{ port, host: 'localhost', family }],
198+
noop);
189199
for (const fn of portHostOptFns) {
190200
fn();
191201
}
@@ -198,20 +208,22 @@ function asyncFailToConnect(port) {
198208
});
199209

200210
const dont = () => common.mustNotCall();
211+
const family = 4;
201212
// connect(port, cb) and connect(port)
202-
const portArgFunctions = doConnect([port], dont);
213+
const portArgFunctions = doConnect([{ port, family }], dont);
203214
for (const fn of portArgFunctions) {
204215
fn().on('error', onError());
205216
}
206217

207218
// connect({port}, cb) and connect({port})
208-
const portOptFunctions = doConnect([{ port }], dont);
219+
const portOptFunctions = doConnect([{ port, family }], dont);
209220
for (const fn of portOptFunctions) {
210221
fn().on('error', onError());
211222
}
212223

213224
// connect({port, host}, cb) and connect({port, host})
214-
const portHostOptFns = doConnect([{ port, host: 'localhost' }], dont);
225+
const portHostOptFns = doConnect([{ port, host: 'localhost', family }],
226+
dont);
215227
for (const fn of portHostOptFns) {
216228
fn().on('error', onError());
217229
}

test/parallel/test-net-pingpong.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ const tmpdir = require('../common/tmpdir');
130130
tmpdir.refresh();
131131
pingPongTest(common.PIPE);
132132
pingPongTest(0);
133-
pingPongTest(0, 'localhost');
133+
pingPongTest(0, '127.0.0.1');
134134
if (common.hasIPv6)
135135
pingPongTest(0, '::1');

test/parallel/test-net-remote-address-port.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ const server = net.createServer(common.mustCall(function(socket) {
4848
socket.resume();
4949
}, 2));
5050

51-
server.listen(0, 'localhost', function() {
52-
const client = net.createConnection(this.address().port, 'localhost');
53-
const client2 = net.createConnection(this.address().port);
51+
server.listen(0, '127.0.0.1', function() {
52+
const client = net.createConnection({ port: this.address().port, host: 'localhost', family: 4 });
53+
const client2 = net.createConnection({ port: this.address().port, family: 4 });
5454
client.on('connect', function() {
5555
assert.ok(remoteAddrCandidates.includes(client.remoteAddress));
5656
assert.ok(remoteFamilyCandidates.includes(client.remoteFamily));

test/parallel/test-net-writable.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ const net = require('net');
66
const server = net.createServer(common.mustCall(function(s) {
77
server.close();
88
s.end();
9-
})).listen(0, 'localhost', common.mustCall(function() {
10-
const socket = net.connect(this.address().port, 'localhost');
9+
})).listen(0, common.localhostIPv4, common.mustCall(function() {
10+
const socket = net.connect({ port: this.address().port,
11+
host: 'localhost',
12+
family: 4 });
1113
socket.on('end', common.mustCall(() => {
1214
assert.strictEqual(socket.writable, true);
1315
socket.write('hello world');

test/sequential/test-https-connect-localport.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ const assert = require('assert');
1717
res.end();
1818
}));
1919

20-
server.listen(0, 'localhost', common.mustCall(() => {
20+
server.listen(0, common.localhostIPv4, common.mustCall(() => {
2121
const port = server.address().port;
2222
const req = https.get({
2323
host: 'localhost',
2424
pathname: '/',
2525
port,
26-
// family: 4,
26+
family: 4,
2727
localPort: common.PORT,
2828
rejectUnauthorized: false,
2929
}, common.mustCall(() => {

0 commit comments

Comments
 (0)