Skip to content

Commit

Permalink
test: introduce a broadcast helper
Browse files Browse the repository at this point in the history
Introduce a helper - very similar to `common.localhostIPv4` that allows test
runner to override a broadcast address. This is required in certain
scenarios - like FreeBSD jails - since networking acts a bit different.

Refs: nodejs#2472
  • Loading branch information
jbergstroem authored and Trott committed Sep 14, 2015
1 parent 1f842c2 commit beec671
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 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 Down Expand Up @@ -107,6 +108,27 @@ Object.defineProperty(exports, 'localhostIPv4', {
}
});

Object.defineProperty(exports, 'broadcastIPv4', {

get: function() {
if (broadcastIPv4 !== null) return broadcastIPv4;

if (exports.inFreeBSDJail) {
if (process.env.BROADCAST) {
broadcastIPv4 = process.env.BROADCAST;
} else {
// shorter error than above since you'd probably be seeing both
console.error('In a FreeBSD jail. Pass broadcast as \'BROADCAST=\' ' +
'to avoid test failures.');
}
}

if (broadcastIPv4 === null) broadcastIPv4 = '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
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

0 comments on commit beec671

Please sign in to comment.