Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: introduce a broadcast helper #2851

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ exports.tmpDir = path.join(exports.testDir, exports.tmpDirName);
var opensslCli = null;
var inFreeBSDJail = null;
var localhostIPv4 = null;
var broadcastIPv4 = null;

Object.defineProperty(exports, 'inFreeBSDJail', {
get: function() {
Expand All @@ -87,26 +88,19 @@ Object.defineProperty(exports, 'inFreeBSDJail', {
Object.defineProperty(exports, 'localhostIPv4', {
get: function() {
if (localhostIPv4 !== null) return localhostIPv4;

if (exports.inFreeBSDJail) {
// Jailed network interfaces are a bit special - since we need to jump
// through loops, as well as this being an exception case, assume the
// user will provide this instead.
if (process.env.LOCALHOST) {
localhostIPv4 = process.env.LOCALHOST;
} else {
console.error('Looks like we\'re in a FreeBSD Jail. ' +
'Please provide your default interface address ' +
'as LOCALHOST or expect some tests to fail.');
}
}

if (localhostIPv4 === null) localhostIPv4 = '127.0.0.1';

localhostIPv4 = getEnvironmentDefault('LOCALHOST', '127.0.0.1');
return localhostIPv4;
}
});

Object.defineProperty(exports, 'broadcastIPv4', {
get: function() {
if (broadcastIPv4 !== null) return broadcastIPv4;
broadcastIPv4 = getEnvironmentDefault('BROADCAST', '255.255.255.255');
return broadcastIPv4;
}
});

// opensslCli defined lazily to reduce overhead of spawnSync
Object.defineProperty(exports, 'opensslCli', {get: function() {
if (opensslCli !== null) return opensslCli;
Expand Down Expand Up @@ -168,6 +162,22 @@ var util = require('util');
for (var i in util) exports[i] = util[i];
//for (var i in exports) global[i] = exports[i];

function getEnvironmentDefault(environ, defaultValue) {
let value = null;
if (exports.inFreeBSDJail) {
if (process.env[environ]) {
value = process.env[environ];
} else {
console.error('In a FreeBSD jail. You might have to override the value ' +
'by passing %s=\'value\' to avoid any test ' +
'failures', environ);
}
}

if (value === null) value = defaultValue;
return value;
}

function protoCtrChain(o) {
var result = [];
for (; o; o = o.__proto__) { result.push(o.constructor); }
Expand Down
2 changes: 1 addition & 1 deletion test/internet/test-dgram-broadcast-multi-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var common = require('../common'),
networkInterfaces = require('os').networkInterfaces(),
Buffer = require('buffer').Buffer,
fork = require('child_process').fork,
LOCAL_BROADCAST_HOST = '255.255.255.255',
LOCAL_BROADCAST_HOST = common.broadcastIPv4,
TIMEOUT = common.platformTimeout(5000),
messages = [
new Buffer('First message to send'),
Expand Down