Only listen on 127.0.0.1 (unless overriden by environment) during test runs by default.

This commit is contained in:
Daniel Patterson 2018-04-03 16:36:45 -07:00 committed by Patrick Niklaus
parent 649d4ee512
commit eae9e7fab6
3 changed files with 9 additions and 8 deletions

View File

@ -47,7 +47,7 @@ class OSRMBaseLoader{
if (err) { if (err) {
if (retryCount < 10) { if (retryCount < 10) {
retryCount++; retryCount++;
setTimeout(() => { tryConnect(this.scope.OSRM_PORT, retry); }, 10); setTimeout(() => { tryConnect(this.scope.OSRM_IP, this.scope.OSRM_PORT, retry); }, 10);
} else { } else {
callback(new Error("Could not connect to osrm-routed after ten retries.")); callback(new Error("Could not connect to osrm-routed after ten retries."));
} }
@ -58,7 +58,7 @@ class OSRMBaseLoader{
} }
}; };
tryConnect(this.scope.OSRM_PORT, retry); tryConnect(this.scope.OSRM_IP, this.scope.OSRM_PORT, retry);
} }
}; };
@ -77,7 +77,7 @@ class OSRMDirectLoader extends OSRMBaseLoader {
osrmUp (callback) { osrmUp (callback) {
if (this.osrmIsRunning()) return callback(new Error("osrm-routed already running!")); if (this.osrmIsRunning()) return callback(new Error("osrm-routed already running!"));
const command_arguments = util.format('%s -p %d -a %s', this.inputFile, this.scope.OSRM_PORT, this.scope.ROUTING_ALGORITHM); const command_arguments = util.format('%s -p %d -i %s -a %s', this.inputFile, this.scope.OSRM_PORT, this.scope.OSRM_HOST, this.scope.ROUTING_ALGORITHM);
this.child = this.scope.runBin('osrm-routed', command_arguments, this.scope.environment, (err) => { this.child = this.scope.runBin('osrm-routed', command_arguments, this.scope.environment, (err) => {
if (err && err.signal !== 'SIGINT') { if (err && err.signal !== 'SIGINT') {
this.child = null; this.child = null;
@ -116,7 +116,7 @@ class OSRMDatastoreLoader extends OSRMBaseLoader {
osrmUp (callback) { osrmUp (callback) {
if (this.osrmIsRunning()) return callback(); if (this.osrmIsRunning()) return callback();
const command_arguments = util.format('--shared-memory=1 -p %d -a %s', this.scope.OSRM_PORT, this.scope.ROUTING_ALGORITHM); const command_arguments = util.format('--shared-memory=1 -i %s -p %d -a %s', this.scope.OSRM_IP, this.scope.OSRM_PORT, this.scope.ROUTING_ALGORITHM);
this.child = this.scope.runBin('osrm-routed', command_arguments, this.scope.environment, (err) => { this.child = this.scope.runBin('osrm-routed', command_arguments, this.scope.environment, (err) => {
if (err && err.signal !== 'SIGINT') { if (err && err.signal !== 'SIGINT') {
this.child = null; this.child = null;

View File

@ -3,8 +3,8 @@
const net = require('net'); const net = require('net');
const Timeout = require('node-timeout'); const Timeout = require('node-timeout');
module.exports = function tryConnect(port, callback) { module.exports = function tryConnect(host, port, callback) {
net.connect({ port: port, host: '127.0.0.1' }) net.connect({ port: port, host: host })
.on('connect', () => { callback(); }) .on('connect', () => { callback(); })
.on('error', () => { .on('error', () => {
callback(new Error('Could not connect.')); callback(new Error('Could not connect.'));

View File

@ -43,7 +43,8 @@ module.exports = function () {
this.TIMEZONE_NAMES = this.PLATFORM_WINDOWS ? 'win' : 'iana'; this.TIMEZONE_NAMES = this.PLATFORM_WINDOWS ? 'win' : 'iana';
this.OSRM_PORT = process.env.OSRM_PORT && parseInt(process.env.OSRM_PORT) || 5000; this.OSRM_PORT = process.env.OSRM_PORT && parseInt(process.env.OSRM_PORT) || 5000;
this.HOST = 'http://127.0.0.1:' + this.OSRM_PORT; this.OSRM_IP = process.env.OSRM_IP || '127.0.0.1';
this.HOST = `http://${this.OSRM_IP}:${this.OSRM_PORT}`;
this.OSRM_PROFILE = process.env.OSRM_PROFILE; this.OSRM_PROFILE = process.env.OSRM_PROFILE;
@ -93,7 +94,7 @@ module.exports = function () {
}; };
this.verifyOSRMIsNotRunning = (callback) => { this.verifyOSRMIsNotRunning = (callback) => {
tryConnect(this.OSRM_PORT, (err) => { tryConnect(this.OSRM_IP, this.OSRM_PORT, (err) => {
if (!err) return callback(new Error('*** osrm-routed is already running.')); if (!err) return callback(new Error('*** osrm-routed is already running.'));
else callback(); else callback();
}); });