Close GH-2795: Rewrite cucumber test caching (and support logic). Fixes #2745
This commit is contained in:
committed by
Moritz Kobitzsch
parent
b2bc169547
commit
c1041e5a64
@@ -2,19 +2,23 @@ var util = require('util');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var d3 = require('d3-queue');
|
||||
var OSM = require('../support/build_osm');
|
||||
var OSM = require('../lib/osm');
|
||||
|
||||
module.exports = function () {
|
||||
this.Given(/^the profile "([^"]*)"$/, (profile, callback) => {
|
||||
this.setProfile(profile, callback);
|
||||
this.profile = profile;
|
||||
this.profileFile = path.join(this.PROFILES_PATH, this.profile + '.lua');
|
||||
callback();
|
||||
});
|
||||
|
||||
this.Given(/^the extract extra arguments "(.*?)"$/, (args, callback) => {
|
||||
this.setExtractArgs(args, callback);
|
||||
this.extractArgs = this.expandOptions(args);
|
||||
callback();
|
||||
});
|
||||
|
||||
this.Given(/^the contract extra arguments "(.*?)"$/, (args, callback) => {
|
||||
this.setContractArgs(args, callback);
|
||||
this.contractArgs = this.expandOptions(args);
|
||||
callback();
|
||||
});
|
||||
|
||||
this.Given(/^a grid size of ([0-9.]+) meters$/, (meters, callback) => {
|
||||
@@ -228,58 +232,46 @@ module.exports = function () {
|
||||
});
|
||||
|
||||
this.Given(/^the raster source$/, (data, callback) => {
|
||||
this.updateFingerprintExtract(data);
|
||||
fs.writeFile(path.resolve(this.TEST_FOLDER, 'rastersource.asc'), data, callback);
|
||||
// TODO: Don't overwrite if it exists
|
||||
fs.writeFile(this.rasterCacheFile, data, callback);
|
||||
// we need this to pass it to the profiles
|
||||
this.environment = Object.assign({OSRM_RASTER_SOURCE: this.rasterCacheFile}, this.environment);
|
||||
});
|
||||
|
||||
this.Given(/^the speed file$/, (data, callback) => {
|
||||
this.updateFingerprintContract(data);
|
||||
fs.writeFile(path.resolve(this.TEST_FOLDER, 'speeds.csv'), data, callback);
|
||||
// TODO: Don't overwrite if it exists
|
||||
fs.writeFile(this.speedsCacheFile, data, callback);
|
||||
});
|
||||
|
||||
this.Given(/^the turn penalty file$/, (data, callback) => {
|
||||
this.updateFingerprintContract(data);
|
||||
fs.writeFile(path.resolve(this.TEST_FOLDER, 'penalties.csv'), data, callback);
|
||||
// TODO: Don't overwrite if it exists
|
||||
fs.writeFile(this.penaltiesCacheFile, data, callback);
|
||||
});
|
||||
|
||||
this.Given(/^the data has been saved to disk$/, (callback) => {
|
||||
try {
|
||||
this.reprocess(callback);
|
||||
} catch(e) {
|
||||
this.processError = e;
|
||||
callback(e);
|
||||
}
|
||||
this.reprocess(callback);
|
||||
});
|
||||
|
||||
this.Given(/^the data has been extracted$/, (callback) => {
|
||||
this.osmData.populate(() => {
|
||||
this.writeAndExtract((err) => {
|
||||
if (err) this.processError = err;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
this.reprocess(callback);
|
||||
});
|
||||
|
||||
this.Given(/^the data has been contracted$/, (callback) => {
|
||||
this.reprocess((err) => {
|
||||
if (err) this.processError = err;
|
||||
callback();
|
||||
});
|
||||
this.reprocess(callback);
|
||||
});
|
||||
|
||||
this.Given(/^osrm\-routed is stopped$/, (callback) => {
|
||||
this.OSRMLoader.shutdown((err) => {
|
||||
if (err) this.processError = err;
|
||||
callback();
|
||||
});
|
||||
this.OSRMLoader.shutdown(callback);
|
||||
});
|
||||
|
||||
this.Given(/^data is loaded directly/, () => {
|
||||
this.loadMethod = 'directly';
|
||||
this.Given(/^data is loaded directly/, (callback) => {
|
||||
this.osrmLoader.setLoadMethod('directly');
|
||||
callback();
|
||||
});
|
||||
|
||||
this.Given(/^data is loaded with datastore$/, () => {
|
||||
this.loadMethod = 'datastore';
|
||||
this.Given(/^data is loaded with datastore$/, (callback) => {
|
||||
this.osrmLoader.setLoadMethod('datastore');
|
||||
callback();
|
||||
});
|
||||
|
||||
this.Given(/^the HTTP method "([^"]*)"$/, (method, callback) => {
|
||||
|
||||
@@ -53,8 +53,6 @@ module.exports = function () {
|
||||
});
|
||||
|
||||
var testRow = (row, ri, cb) => {
|
||||
var ok = true;
|
||||
|
||||
for (var k in result[ri]) {
|
||||
if (this.FuzzyMatch.match(result[ri][k], row[k])) {
|
||||
result[ri][k] = row[k];
|
||||
@@ -62,15 +60,9 @@ module.exports = function () {
|
||||
result[ri][k] = '';
|
||||
} else {
|
||||
result[ri][k] = result[ri][k].toString();
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
var failed = { attempt: 'distance_matrix', query: this.query, response: response };
|
||||
this.logFail(row, result[ri], [failed]);
|
||||
}
|
||||
|
||||
result[ri][''] = row[''];
|
||||
cb(null, result[ri]);
|
||||
};
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
var util = require('util');
|
||||
|
||||
module.exports = function () {
|
||||
this.Before((scenario, callback) => {
|
||||
this.scenarioTitle = scenario.getName();
|
||||
|
||||
this.loadMethod = this.DEFAULT_LOAD_METHOD;
|
||||
this.queryParams = {};
|
||||
var d = new Date();
|
||||
this.scenarioTime = util.format('%d-%d-%dT%s:%s:%sZ', d.getFullYear(), d.getMonth()+1, d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds());
|
||||
this.resetData();
|
||||
this.hasLoggedPreprocessInfo = false;
|
||||
this.hasLoggedScenarioInfo = false;
|
||||
this.setGridSize(this.DEFAULT_GRID_SIZE);
|
||||
this.setOrigin(this.DEFAULT_ORIGIN);
|
||||
callback();
|
||||
});
|
||||
};
|
||||
@@ -157,7 +157,6 @@ module.exports = function () {
|
||||
} else {
|
||||
got.matchings = encodedResult;
|
||||
row.matchings = extendedTarget;
|
||||
this.logFail(row, got, { matching: { query: this.query, response: res } });
|
||||
}
|
||||
|
||||
cb(null, got);
|
||||
|
||||
@@ -22,24 +22,16 @@ module.exports = function () {
|
||||
|
||||
var got = { in: row.in, out: row.out };
|
||||
|
||||
var ok = true;
|
||||
|
||||
Object.keys(row).forEach((key) => {
|
||||
if (key === 'out') {
|
||||
if (this.FuzzyMatch.matchLocation(coord, outNode)) {
|
||||
got[key] = row[key];
|
||||
} else {
|
||||
row[key] = util.format('%s [%d,%d]', row[key], outNode.lat, outNode.lon);
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!ok) {
|
||||
var failed = { attempt: 'nearest', query: this.query, response: response };
|
||||
this.logFail(row, got, [failed]);
|
||||
}
|
||||
|
||||
cb(null, got);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -2,36 +2,58 @@ var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
|
||||
module.exports = function () {
|
||||
this.When(/^I run "osrm\-routed\s?(.*?)"$/, { timeout: this.TIMEOUT }, (options, callback) => {
|
||||
this.runBin('osrm-routed', options, () => {
|
||||
callback();
|
||||
this.resetOptionsOutput = () => {
|
||||
this.stdout = null;
|
||||
this.stderr = null;
|
||||
this.exitCode = null;
|
||||
this.termSignal = null;
|
||||
};
|
||||
|
||||
this.runAndSafeOutput = (binary, options, callback) => {
|
||||
this.runBin(binary, this.expandOptions(options), this.environment, (err, stdout, stderr) => {
|
||||
this.stdout = stdout;
|
||||
this.stderr = stderr;
|
||||
this.exitCode = err && err.code || 0;
|
||||
this.termSignal = err && err.signal || '';
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
this.When(/^I run "osrm\-routed\s?(.*?)"$/, { timeout: this.TIMEOUT }, (options, callback) => {
|
||||
this.runAndSafeOutput('osrm-routed', options, callback);
|
||||
});
|
||||
|
||||
this.When(/^I run "osrm\-extract\s?(.*?)"$/, (options, callback) => {
|
||||
this.runBin('osrm-extract', options, () => {
|
||||
callback();
|
||||
});
|
||||
this.runAndSafeOutput('osrm-extract', options, callback);
|
||||
});
|
||||
|
||||
this.When(/^I run "osrm\-contract\s?(.*?)"$/, (options, callback) => {
|
||||
this.runBin('osrm-contract', options, () => {
|
||||
callback();
|
||||
});
|
||||
this.runAndSafeOutput('osrm-contract', options, callback);
|
||||
});
|
||||
|
||||
this.When(/^I try to run "osrm\-routed\s?(.*?)"$/, (options, callback) => {
|
||||
this.runAndSafeOutput('osrm-routed', options, () => { callback(); });
|
||||
});
|
||||
|
||||
this.When(/^I try to run "osrm\-extract\s?(.*?)"$/, (options, callback) => {
|
||||
this.runAndSafeOutput('osrm-extract', options, () => { callback(); });
|
||||
});
|
||||
|
||||
this.When(/^I try to run "osrm\-contract\s?(.*?)"$/, (options, callback) => {
|
||||
this.runAndSafeOutput('osrm-contract', options, () => { callback(); });
|
||||
});
|
||||
|
||||
this.When(/^I run "osrm\-datastore\s?(.*?)"$/, (options, callback) => {
|
||||
this.runBin('osrm-datastore', options, () => {
|
||||
callback();
|
||||
});
|
||||
this.runAndSafeOutput('osrm-datastore', options, callback);
|
||||
});
|
||||
|
||||
this.Then(/^it should exit with code (\d+)$/, (code) => {
|
||||
assert.equal(this.exitCode, parseInt(code));
|
||||
this.Then(/^it should exit successfully$/, () => {
|
||||
assert.equal(this.exitCode, 0);
|
||||
assert.equal(this.termSignal, '');
|
||||
});
|
||||
|
||||
this.Then(/^it should exit with code not (\d+)$/, (code) => {
|
||||
assert.notEqual(this.exitCode, parseInt(code));
|
||||
this.Then(/^it should exit with an error$/, () => {
|
||||
assert.ok(this.exitCode !== 0 || this.termSignal);
|
||||
});
|
||||
|
||||
this.Then(/^stdout should contain "(.*?)"$/, (str) => {
|
||||
@@ -65,7 +87,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.processedCacheFile + '.datasource_names', {encoding:'UTF-8'}).trim().split('\n').join(',');
|
||||
assert.equal(actualData, expectedData);
|
||||
});
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ module.exports = function () {
|
||||
});
|
||||
|
||||
this.Then(/^"([^"]*)" should return code (\d+)$/, (binary, code) => {
|
||||
assert.ok(this.processError instanceof this.OSRMError);
|
||||
assert.ok(this.processError instanceof Error);
|
||||
assert.equal(this.processError.process, binary);
|
||||
assert.equal(parseInt(this.processError.code), parseInt(code));
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@ module.exports = function () {
|
||||
}
|
||||
|
||||
this.reprocessAndLoadData((e) => {
|
||||
if (e) callback(e);
|
||||
if (e) return callback(e);
|
||||
var testRow = (row, i, cb) => {
|
||||
var outputRow = row;
|
||||
|
||||
@@ -41,10 +41,6 @@ module.exports = function () {
|
||||
}
|
||||
});
|
||||
|
||||
if (outputRow != row) {
|
||||
this.logFail(row, outputRow, result);
|
||||
}
|
||||
|
||||
cb(null, outputRow);
|
||||
});
|
||||
};
|
||||
@@ -116,7 +112,7 @@ module.exports = function () {
|
||||
sq.defer(parseRes, key);
|
||||
});
|
||||
|
||||
sq.awaitAll(() => { cb(null, result); });
|
||||
sq.awaitAll((err) => { cb(err, result); });
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -85,23 +85,14 @@ module.exports = function () {
|
||||
} else {
|
||||
got.trips = encodedResult;
|
||||
got.trips = extendedTarget;
|
||||
this.logFail(row, got, { trip: { query: this.query, response: res }});
|
||||
}
|
||||
|
||||
ok = true;
|
||||
|
||||
for (var key in row) {
|
||||
if (this.FuzzyMatch.match(got[key], row[key])) {
|
||||
got[key] = row[key];
|
||||
} else {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
this.logFail(row, got, { trip: { query: this.query, response: res }});
|
||||
}
|
||||
|
||||
cb(null, got);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user