2016-09-19 17:13:44 -04:00
|
|
|
'use strict';
|
2016-03-04 15:11:05 -05:00
|
|
|
|
2016-09-19 17:13:44 -04:00
|
|
|
const path = require('path');
|
|
|
|
const util = require('util');
|
|
|
|
const fs = require('fs');
|
|
|
|
const d3 = require('d3-queue');
|
|
|
|
const child_process = require('child_process');
|
|
|
|
const tryConnect = require('../lib/try_connect');
|
|
|
|
|
|
|
|
// Sets up all constants that are valid for all features
|
2016-03-04 15:11:05 -05:00
|
|
|
module.exports = function () {
|
|
|
|
this.initializeEnv = (callback) => {
|
2016-05-26 14:01:53 -04:00
|
|
|
this.TIMEOUT = process.env.CUCUMBER_TIMEOUT && parseInt(process.env.CUCUMBER_TIMEOUT) || 5000;
|
2016-09-19 17:13:44 -04:00
|
|
|
// set cucumber default timeout
|
2016-05-05 12:36:30 -04:00
|
|
|
this.setDefaultTimeout(this.TIMEOUT);
|
2016-09-19 17:13:44 -04:00
|
|
|
this.ROOT_PATH = process.cwd();
|
|
|
|
|
|
|
|
this.TEST_PATH = path.resolve(this.ROOT_PATH, 'test');
|
|
|
|
this.CACHE_PATH = path.resolve(this.TEST_PATH, 'cache');
|
|
|
|
this.LOGS_PATH = path.resolve(this.TEST_PATH, 'logs');
|
|
|
|
|
|
|
|
this.PROFILES_PATH = path.resolve(this.ROOT_PATH, 'profiles');
|
|
|
|
this.FIXTURES_PATH = path.resolve(this.ROOT_PATH, 'unit_tests/fixtures');
|
|
|
|
this.BIN_PATH = process.env.OSRM_BUILD_DIR && process.env.OSRM_BUILD_DIR || path.resolve(this.ROOT_PATH, 'build');
|
|
|
|
var stxxl_config = path.resolve(this.ROOT_PATH, 'test/.stxxl');
|
|
|
|
if (!fs.existsSync(stxxl_config)) {
|
|
|
|
return callback(new Error('*** '+stxxl_config+ 'does not exist'));
|
|
|
|
}
|
|
|
|
|
2017-01-13 08:19:04 -05:00
|
|
|
this.PLATFORM_WINDOWS = process.platform.match(/^win.*/);
|
2016-09-19 17:13:44 -04:00
|
|
|
this.DEFAULT_ENVIRONMENT = Object.assign({STXXLCFG: stxxl_config}, process.env);
|
|
|
|
this.DEFAULT_PROFILE = 'bicycle';
|
|
|
|
this.DEFAULT_INPUT_FORMAT = 'osm';
|
2017-02-13 14:08:18 -05:00
|
|
|
this.DEFAULT_LOAD_METHOD = 'datastore';
|
2016-09-19 17:13:44 -04:00
|
|
|
this.DEFAULT_ORIGIN = [1,1];
|
2016-03-04 15:11:05 -05:00
|
|
|
this.OSM_USER = 'osrm';
|
|
|
|
this.OSM_UID = 1;
|
|
|
|
this.OSM_TIMESTAMP = '2000-01-01T00:00:00Z';
|
|
|
|
this.WAY_SPACING = 100;
|
2016-09-19 17:13:44 -04:00
|
|
|
this.DEFAULT_GRID_SIZE = 100; // meters
|
2017-03-11 03:26:12 -05:00
|
|
|
// get algorithm name from the command line profile argument
|
2017-05-11 06:13:52 -04:00
|
|
|
this.ROUTING_ALGORITHM = process.argv[process.argv.indexOf('-p') + 1].match('mld') ? 'MLD' : 'CH';
|
2017-06-02 11:08:52 -04:00
|
|
|
this.TIMEZONE_NAMES = this.PLATFORM_WINDOWS ? 'win' : 'iana';
|
2016-09-19 17:13:44 -04:00
|
|
|
|
|
|
|
this.OSRM_PORT = process.env.OSRM_PORT && parseInt(process.env.OSRM_PORT) || 5000;
|
|
|
|
this.HOST = 'http://127.0.0.1:' + this.OSRM_PORT;
|
2016-03-04 15:11:05 -05:00
|
|
|
|
2017-01-13 08:19:04 -05:00
|
|
|
if (this.PLATFORM_WINDOWS) {
|
2016-03-04 15:11:05 -05:00
|
|
|
this.TERMSIGNAL = 9;
|
|
|
|
this.EXE = '.exe';
|
|
|
|
} else {
|
|
|
|
this.TERMSIGNAL = 'SIGTERM';
|
|
|
|
this.EXE = '';
|
2016-12-26 13:00:08 -05:00
|
|
|
}
|
2016-10-04 06:02:34 -04:00
|
|
|
|
2016-12-26 13:00:08 -05:00
|
|
|
// heuristically detect .so/.a/.dll/.lib suffix
|
|
|
|
this.LIB = ['lib%s.a', 'lib%s.so', '%s.dll', '%s.lib'].find((format) => {
|
2016-10-04 06:02:34 -04:00
|
|
|
try {
|
2016-12-26 13:00:08 -05:00
|
|
|
const lib = this.BIN_PATH + '/' + util.format(format, 'osrm');
|
|
|
|
fs.accessSync(lib, fs.F_OK);
|
|
|
|
} catch(e) { return false; }
|
|
|
|
return true;
|
|
|
|
});
|
2016-10-04 06:02:34 -04:00
|
|
|
|
2016-12-26 13:00:08 -05:00
|
|
|
if (this.LIB === undefined) {
|
|
|
|
throw new Error('*** Unable to detect dynamic or static libosrm libraries');
|
2016-03-04 15:11:05 -05:00
|
|
|
}
|
|
|
|
|
2016-09-19 17:13:44 -04:00
|
|
|
this.OSRM_EXTRACT_PATH = path.resolve(util.format('%s/%s%s', this.BIN_PATH, 'osrm-extract', this.EXE));
|
|
|
|
this.OSRM_CONTRACT_PATH = path.resolve(util.format('%s/%s%s', this.BIN_PATH, 'osrm-contract', this.EXE));
|
|
|
|
this.OSRM_ROUTED_PATH = path.resolve(util.format('%s/%s%s', this.BIN_PATH, 'osrm-routed', this.EXE));
|
2016-12-26 13:00:08 -05:00
|
|
|
this.LIB_OSRM_EXTRACT_PATH = util.format('%s/' + this.LIB, this.BIN_PATH, 'osrm_extract'),
|
|
|
|
this.LIB_OSRM_CONTRACT_PATH = util.format('%s/' + this.LIB, this.BIN_PATH, 'osrm_contract'),
|
|
|
|
this.LIB_OSRM_PATH = util.format('%s/' + this.LIB, this.BIN_PATH, 'osrm');
|
2016-09-19 17:13:44 -04:00
|
|
|
|
2016-03-04 15:11:05 -05:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.info(util.format('Node Version', process.version));
|
2016-10-04 06:02:34 -04:00
|
|
|
if (parseInt(process.version.match(/v(\d)/)[1]) < 4) throw new Error('*** Please upgrade to Node 4.+ to run OSRM cucumber tests');
|
2016-03-04 15:11:05 -05:00
|
|
|
|
2016-09-19 17:13:44 -04:00
|
|
|
fs.exists(this.TEST_PATH, (exists) => {
|
|
|
|
if (exists)
|
|
|
|
return callback();
|
|
|
|
else
|
|
|
|
return callback(new Error('*** Test folder doesn\'t exist.'));
|
2016-03-04 15:11:05 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-09-19 17:13:44 -04:00
|
|
|
this.getProfilePath = (profile) => {
|
|
|
|
return path.resolve(this.PROFILES_PATH, profile + '.lua');
|
|
|
|
};
|
|
|
|
|
|
|
|
this.verifyOSRMIsNotRunning = (callback) => {
|
|
|
|
tryConnect(this.OSRM_PORT, (err) => {
|
|
|
|
if (!err) return callback(new Error('*** osrm-routed is already running.'));
|
|
|
|
else callback();
|
|
|
|
});
|
2016-03-04 15:11:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
this.verifyExistenceOfBinaries = (callback) => {
|
2016-09-19 17:13:44 -04:00
|
|
|
var verify = (binPath, cb) => {
|
2016-03-04 15:11:05 -05:00
|
|
|
fs.exists(binPath, (exists) => {
|
2016-09-19 17:13:44 -04:00
|
|
|
if (!exists) return cb(new Error(util.format('%s is missing. Build failed?', binPath)));
|
2016-12-26 13:00:08 -05:00
|
|
|
var helpPath = util.format('%s --help', binPath);
|
2016-09-19 17:13:44 -04:00
|
|
|
child_process.exec(helpPath, (err) => {
|
2016-03-04 15:11:05 -05:00
|
|
|
if (err) {
|
2016-09-19 17:13:44 -04:00
|
|
|
return cb(new Error(util.format('*** %s exited with code %d', helpPath, err.code)));
|
2016-03-04 15:11:05 -05:00
|
|
|
}
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var q = d3.queue();
|
2016-09-19 17:13:44 -04:00
|
|
|
[this.OSRM_EXTRACT_PATH, this.OSRM_CONTRACT_PATH, this.OSRM_ROUTED_PATH].forEach(bin => { q.defer(verify, bin); });
|
|
|
|
q.awaitAll(callback);
|
2016-03-04 15:11:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
process.on('exit', () => {
|
2016-09-19 17:13:44 -04:00
|
|
|
this.osrmLoader.shutdown(() => {});
|
2016-03-04 15:11:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
process.on('SIGINT', () => {
|
|
|
|
process.exit(2);
|
|
|
|
// TODO need to handle for windows??
|
|
|
|
});
|
|
|
|
};
|