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'));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.DEFAULT_ENVIRONMENT = Object.assign({STXXLCFG: stxxl_config}, process.env);
|
|
|
|
this.DEFAULT_PROFILE = 'bicycle';
|
|
|
|
this.DEFAULT_INPUT_FORMAT = 'osm';
|
|
|
|
this.DEFAULT_LOAD_METHOD = 'datastore';
|
|
|
|
this.DEFAULT_ORIGIN = [1,1];
|
2016-03-04 15:11:05 -05:00
|
|
|
this.OSM_USER = 'osrm';
|
|
|
|
this.OSM_GENERATOR = 'osrm-test';
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// TODO make sure this works on win
|
|
|
|
if (process.platform.match(/indows.*/)) {
|
|
|
|
this.TERMSIGNAL = 9;
|
|
|
|
this.EXE = '.exe';
|
2016-05-28 15:09:21 -04:00
|
|
|
this.LIB = '.dll';
|
2016-03-04 15:11:05 -05:00
|
|
|
this.QQ = '"';
|
|
|
|
} else {
|
|
|
|
this.TERMSIGNAL = 'SIGTERM';
|
|
|
|
this.EXE = '';
|
2016-09-19 17:13:44 -04:00
|
|
|
// TODO autodetect if this was build with shared or static libraries
|
|
|
|
this.LIB = process.env.BUILD_SHARED_LIBS && '.so' || '.a';
|
2016-03-04 15:11:05 -05:00
|
|
|
this.QQ = '';
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
this.LIB_OSRM_EXTRACT_PATH = util.format('%s/libosrm_extract%s', this.BIN_PATH, this.LIB),
|
|
|
|
this.LIB_OSRM_CONTRACT_PATH = util.format('%s/libosrm_contract%s', this.BIN_PATH, this.LIB),
|
|
|
|
this.LIB_OSRM_PATH = util.format('%s/libosrm%s', this.BIN_PATH, this.LIB);
|
|
|
|
|
2016-03-04 15:11:05 -05:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.info(util.format('Node Version', process.version));
|
|
|
|
if (parseInt(process.version.match(/v(\d)/)[1]) < 4) throw new Error('*** PLease upgrade to Node 4.+ to run OSRM cucumber tests');
|
|
|
|
|
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-05-27 11:34:20 -04:00
|
|
|
var helpPath = util.format('%s --help > /dev/null 2>&1', 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??
|
|
|
|
});
|
|
|
|
};
|