diff --git a/features/step_definitions/data.js b/features/step_definitions/data.js index 6026c0f91..bb58b8511 100644 --- a/features/step_definitions/data.js +++ b/features/step_definitions/data.js @@ -228,14 +228,17 @@ module.exports = function () { }); this.Given(/^the raster source$/, (data, callback) => { + this.updateFingerprintExtract(data); fs.writeFile(path.resolve(this.TEST_FOLDER, 'rastersource.asc'), data, callback); }); this.Given(/^the speed file$/, (data, callback) => { + this.updateFingerprintContract(data); fs.writeFile(path.resolve(this.TEST_FOLDER, 'speeds.csv'), data, callback); }); this.Given(/^the turn penalty file$/, (data, callback) => { + this.updateFingerprintContract(data); fs.writeFile(path.resolve(this.TEST_FOLDER, 'penalties.csv'), data, callback); }); @@ -249,9 +252,11 @@ module.exports = function () { }); this.Given(/^the data has been extracted$/, (callback) => { - this.writeAndExtract((err) => { - if (err) this.processError = err; - callback(); + this.osmData.populate(() => { + this.writeAndExtract((err) => { + if (err) this.processError = err; + callback(); + }); }); }); diff --git a/features/step_definitions/options.js b/features/step_definitions/options.js index e310d3fb2..2f67f523b 100644 --- a/features/step_definitions/options.js +++ b/features/step_definitions/options.js @@ -61,7 +61,7 @@ module.exports = function () { }); this.Then(/^datasource names should contain "(.+)"$/, (expectedData) => { - var actualData = fs.readFileSync(this.osmData.extractedFile+'.osrm.datasource_names',{encoding:'UTF-8'}).trim().split('\n').join(','); + var actualData = fs.readFileSync(this.osmData.extractedFile + '.osrm.datasource_names', {encoding:'UTF-8'}).trim().split('\n').join(','); assert.equal(actualData, expectedData); }); diff --git a/features/support/config.js b/features/support/config.js index 1d62030a5..169cf434e 100644 --- a/features/support/config.js +++ b/features/support/config.js @@ -59,7 +59,6 @@ module.exports = function () { var hashContract = (cb) => { this.hashOfFiles(util.format('%s/osrm-contract%s', this.BIN_PATH, this.EXE), (hash) => { this.binContractHash = hash; - this.fingerprintContract = this.hashString(this.binContractHash); cb(); }); }; @@ -79,16 +78,18 @@ module.exports = function () { .defer(hashContract) .defer(hashRouted) .awaitAll(() => { - this.fingerprintExtract = this.hashString([this.profileHash, this.luaLibHash, this.binExtractHash].join('-')); this.AfterConfiguration(() => { callback(); }); }); }; - this.setProfileBasedHashes = () => { - this.fingerprintExtract = this.hashString([this.profileHash, this.luaLibHash, this.binExtractHash].join('-')); - this.fingerprintContract = this.hashString(this.binContractHash); + this.updateFingerprintExtract = (str) => { + this.fingerprintExtract = this.hashString([this.fingerprintExtract, str].join('-')); + }; + + this.updateFingerprintContract = (str) => { + this.fingerprintContract = this.hashString([this.fingerprintContract, str].join('-')); }; this.setProfile = (profile, cb) => { @@ -97,22 +98,24 @@ module.exports = function () { this.profile = profile; this.hashProfile((hash) => { this.profileHash = hash; - this.setProfileBasedHashes(); + this.updateFingerprintExtract(this.profileHash); cb(); }); - } else cb(); + } else { + this.updateFingerprintExtract(this.profileHash); + cb(); + } }; this.setExtractArgs = (args, callback) => { this.extractArgs = args; - this.forceExtract = true; - this.forceContract = true; + this.updateFingerprintExtract(args); callback(); }; this.setContractArgs = (args, callback) => { this.contractArgs = args; - this.forceContract = true; + this.updateFingerprintContract(args); callback(); }; }; diff --git a/features/support/data.js b/features/support/data.js index 7fad6d057..760266cf8 100644 --- a/features/support/data.js +++ b/features/support/data.js @@ -222,11 +222,12 @@ module.exports = function () { }); }; - ['osrm','osrm.names','osrm.restrictions','osrm.ebg','osrm.enw','osrm.edges','osrm.fileIndex','osrm.geometry','osrm.nodes','osrm.ramIndex','osrm.properties','osrm.icd'].forEach(file => { - q.defer(rename, file); - }); + ['osrm', 'osrm.ebg', 'osrm.edges', 'osrm.enw', 'osrm.fileIndex', 'osrm.geometry', 'osrm.icd', + 'osrm.names', 'osrm.nodes', 'osrm.properties', 'osrm.ramIndex', 'osrm.restrictions'].forEach(file => { + q.defer(rename, file); + }); - ['osrm.edge_segment_lookup','osrm.edge_penalties'].forEach(file => { + ['osrm.edge_penalties', 'osrm.edge_segment_lookup'].forEach(file => { q.defer(renameIfExists, file); }); @@ -260,6 +261,13 @@ module.exports = function () { }); }; + var renameIfExists = (file, cb) => { + fs.stat([this.osmData.extractedFile, file].join('.'), (doesNotExistErr, exists) => { + if (exists) rename(file, cb); + else cb(); + }); + }; + var copy = (file, cb) => { this.log(util.format('Copying %s.%s to %s.%s', this.osmData.extractedFile, file, this.osmData.contractedFile, file), 'preprocess'); fs.createReadStream([this.osmData.extractedFile, file].join('.')) @@ -273,11 +281,17 @@ module.exports = function () { var q = d3.queue(); - ['osrm.hsgr','osrm.fileIndex','osrm.geometry','osrm.nodes','osrm.ramIndex','osrm.core','osrm.edges','osrm.datasource_indexes','osrm.datasource_names','osrm.level','osrm.icd'].forEach((file) => { - q.defer(rename, file); + ['osrm', 'osrm.core', 'osrm.datasource_indexes', 'osrm.datasource_names', 'osrm.ebg','osrm.edges', + 'osrm.enw', 'osrm.fileIndex', 'osrm.geometry', 'osrm.hsgr', 'osrm.icd','osrm.level', 'osrm.names', + 'osrm.nodes', 'osrm.properties', 'osrm.ramIndex', 'osrm.restrictions'].forEach((file) => { + q.defer(rename, file); + }); + + ['osrm.edge_penalties', 'osrm.edge_segment_lookup'].forEach(file => { + q.defer(renameIfExists, file); }); - ['osrm.names','osrm.restrictions','osrm.properties','osrm'].forEach((file) => { + [].forEach((file) => { q.defer(copy, file); }); @@ -292,32 +306,33 @@ module.exports = function () { var noop = (cb) => cb(); this.reprocess = (callback) => { - this.writeAndExtract((e) => { - if (e) return callback(e); + this.osmData.populate(() => { this.isContracted((isContracted) => { - var contractFn = (isContracted && !this.forceContract) ? noop : this.contractData; - if (isContracted) this.log('Already contracted ' + this.osmData.contractedFile, 'preprocess'); - contractFn((e) => { - this.forceContract = false; - if (e) return callback(e); - this.logPreprocessDone(); + if (!isContracted) { + this.writeAndExtract((e) => { + if (e) return callback(e); + this.contractData((e) => { + if (e) return callback(e); + this.logPreprocessDone(); + callback(); + }); + }); + } else { + this.log('Already contracted ' + this.osmData.contractedFile, 'preprocess'); callback(); - }); + } }); }); }; this.writeAndExtract = (callback) => { - this.osmData.populate(() => { - this.writeInputData((e) => { - if (e) return callback(e); - this.isExtracted((isExtracted) => { - var extractFn = (isExtracted && !this.forceExtract) ? noop : this.extractData; - if (isExtracted) this.log('Already extracted ' + this.osmData.extractedFile, 'preprocess'); - extractFn((e) => { - this.forceExtract = false; - callback(e); - }); + this.writeInputData((e) => { + if (e) return callback(e); + this.isExtracted((isExtracted) => { + var extractFn = isExtracted ? noop : this.extractData; + if (isExtracted) this.log('Already extracted ' + this.osmData.extractedFile, 'preprocess'); + extractFn((e) => { + callback(e); }); }); }); diff --git a/features/support/hooks.js b/features/support/hooks.js index 509026408..753bdf760 100644 --- a/features/support/hooks.js +++ b/features/support/hooks.js @@ -20,6 +20,8 @@ module.exports = function () { this.hasLoggedScenarioInfo = false; this.setGridSize(this.DEFAULT_GRID_SIZE); this.setOrigin(this.DEFAULT_ORIGIN); + this.fingerprintExtract = this.hashString([this.luaLibHash, this.binExtractHash].join('-')); + this.fingerprintContract = this.hashString(this.binContractHash); callback(); });