From fe5d1a6e74a01f5c4559aa471c3c52ac4298316d Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Sat, 11 Mar 2017 09:26:12 +0100 Subject: [PATCH] Add MLD testing to cucumber tests --- cucumber.js | 6 +-- features/car/summaries.feature | 2 +- features/options/contract/version.feature | 2 +- features/options/customize/files.feature | 23 +++++++++ features/options/customize/help.feature | 35 +++++++++++++ features/options/customize/invalid.feature | 20 ++++++++ features/options/customize/version.feature | 19 ++++++++ features/options/partition/files.feature | 22 +++++++++ features/options/partition/help.feature | 50 +++++++++++++++++++ features/options/partition/invalid.feature | 20 ++++++++ features/options/partition/version.feature | 19 ++++++++ features/step_definitions/data.js | 16 ++++-- features/step_definitions/options.js | 26 ++-------- features/support/data.js | 57 ++++++++++++++++++++-- features/support/env.js | 4 +- features/support/hooks.js | 2 + features/testbot/loop.feature | 3 +- features/testbot/weight.feature | 2 + package.json | 2 +- src/tools/customize.cpp | 2 +- src/tools/partition.cpp | 2 +- 21 files changed, 295 insertions(+), 39 deletions(-) create mode 100644 features/options/customize/files.feature create mode 100644 features/options/customize/help.feature create mode 100644 features/options/customize/invalid.feature create mode 100644 features/options/customize/version.feature create mode 100644 features/options/partition/files.feature create mode 100644 features/options/partition/help.feature create mode 100644 features/options/partition/invalid.feature create mode 100644 features/options/partition/version.feature diff --git a/cucumber.js b/cucumber.js index 0bf6f570f..5390a9215 100644 --- a/cucumber.js +++ b/cucumber.js @@ -2,8 +2,6 @@ module.exports = { default: '--strict --tags ~@stress --tags ~@todo --require features/support --require features/step_definitions', verify: '--strict --tags ~@stress --tags ~@todo -f progress --require features/support --require features/step_definitions', todo: '--strict --tags @todo --require features/support --require features/step_definitions', - all: '--strict --require features/support --require features/step_definitions' + all: '--strict --require features/support --require features/step_definitions', + mld: '--strict --tags ~@stress --tags ~@todo --tags ~@match --tags ~@alternative --tags ~@traffic --tags ~@weight --tags ~@matrix --tags ~@trip --tags ~@via --require features/support --require features/step_definitions -f progress' } - - - diff --git a/features/car/summaries.feature b/features/car/summaries.feature index 5c14f7b0e..27cb406e7 100644 --- a/features/car/summaries.feature +++ b/features/car/summaries.feature @@ -5,7 +5,7 @@ Feature: Basic Routing Given the profile "car" Given a grid size of 500 meters - @smallest + @smallest @via Scenario: Summaries when routing on a simple network Given the node map """ diff --git a/features/options/contract/version.feature b/features/options/contract/version.feature index 88ec8b734..0c2360890 100644 --- a/features/options/contract/version.feature +++ b/features/options/contract/version.feature @@ -1,4 +1,4 @@ -@prepare @options @version +@contract @options @version Feature: osrm-contract command line options: version # the regex will match these two formats: # v0.3.7.0 # this is the normal format when you build from a git clone diff --git a/features/options/customize/files.feature b/features/options/customize/files.feature new file mode 100644 index 000000000..4c74e26c5 --- /dev/null +++ b/features/options/customize/files.feature @@ -0,0 +1,23 @@ +@customize @options @files +Feature: osrm-contract command line options: files + Background: + Given the profile "testbot" + And the node map + """ + a b + """ + And the ways + | nodes | + | ab | + And the data has been extracted + And the data has been partitioned + + Scenario: osrm-customize - Passing base file + When I run "osrm-customize {processed_file}" + Then it should exit successfully + + Scenario: osrm-customize - Missing input file + When I try to run "osrm-customize over-the-rainbow.osrm" + And stderr should contain "over-the-rainbow.osrm" + And stderr should contain "not found" + And it should exit with an error diff --git a/features/options/customize/help.feature b/features/options/customize/help.feature new file mode 100644 index 000000000..504a5199d --- /dev/null +++ b/features/options/customize/help.feature @@ -0,0 +1,35 @@ +@contract @options @help +Feature: osrm-customize command line options: help + + Scenario: osrm-customize - Help should be shown when no options are passed + When I try to run "osrm-customize" + Then stderr should be empty + And stdout should contain /osrm-customize(.exe)? \[options\]:/ + And stdout should contain "Options:" + And stdout should contain "--version" + And stdout should contain "--help" + And stdout should contain "Configuration:" + And stdout should contain "--threads" + And it should exit with an error + + Scenario: osrm-customize - Help, short + When I run "osrm-customize -h" + Then stderr should be empty + And stdout should contain /osrm-customize(.exe)? \[options\]:/ + And stdout should contain "Options:" + And stdout should contain "--version" + And stdout should contain "--help" + And stdout should contain "Configuration:" + And stdout should contain "--threads" + And it should exit successfully + + Scenario: osrm-customize - Help, long + When I run "osrm-customize --help" + Then stderr should be empty + And stdout should contain /osrm-customize(.exe)? \[options\]:/ + And stdout should contain "Options:" + And stdout should contain "--version" + And stdout should contain "--help" + And stdout should contain "Configuration:" + And stdout should contain "--threads" + And it should exit successfully diff --git a/features/options/customize/invalid.feature b/features/options/customize/invalid.feature new file mode 100644 index 000000000..ec03c4d7a --- /dev/null +++ b/features/options/customize/invalid.feature @@ -0,0 +1,20 @@ +@prepare @options @invalid +Feature: osrm-customize command line options: invalid options + + Background: + Given the profile "testbot" + And the node map + """ + a b + """ + And the ways + | nodes | + | ab | + And the data has been extracted + + Scenario: osrm-customize - Non-existing option + When I try to run "osrm-customize --fly-me-to-the-moon" + Then stdout should be empty + And stderr should contain "option" + And stderr should contain "fly-me-to-the-moon" + And it should exit with an error diff --git a/features/options/customize/version.feature b/features/options/customize/version.feature new file mode 100644 index 000000000..54b5bd531 --- /dev/null +++ b/features/options/customize/version.feature @@ -0,0 +1,19 @@ +@prepare @options @version +Feature: osrm-customize command line options: version + + Background: + Given the profile "testbot" + + Scenario: osrm-customize - Version, short + When I run "osrm-customize --v" + Then stderr should be empty + And stdout should contain 1 line + And stdout should contain /(v\d{1,2}\.\d{1,2}\.\d{1,2}|\w*-\d+-\w+)/ + And it should exit successfully + + Scenario: osrm-customize - Version, long + When I run "osrm-customize --version" + Then stderr should be empty + And stdout should contain 1 line + And stdout should contain /(v\d{1,2}\.\d{1,2}\.\d{1,2}|\w*-\d+-\w+)/ + And it should exit successfully diff --git a/features/options/partition/files.feature b/features/options/partition/files.feature new file mode 100644 index 000000000..b9fd151b3 --- /dev/null +++ b/features/options/partition/files.feature @@ -0,0 +1,22 @@ +@partition @options @files +Feature: osrm-partition command line options: files + Background: + Given the profile "testbot" + And the node map + """ + a b + """ + And the ways + | nodes | + | ab | + And the data has been extracted + + Scenario: osrm-partition - Passing base file + When I run "osrm-partition {processed_file}" + Then it should exit successfully + + Scenario: osrm-partition - Missing input file + When I try to run "osrm-partition over-the-rainbow.osrm" + And stderr should contain "over-the-rainbow.osrm" + And stderr should contain "not found" + And it should exit with an error diff --git a/features/options/partition/help.feature b/features/options/partition/help.feature new file mode 100644 index 000000000..e757628f9 --- /dev/null +++ b/features/options/partition/help.feature @@ -0,0 +1,50 @@ +@partition @options @help +Feature: osrm-partition command line options: help + + Scenario: osrm-partition - Help should be shown when no options are passed + When I try to run "osrm-partition" + Then stderr should be empty + And stdout should contain /osrm-partition(.exe)? \[options\]:/ + And stdout should contain "Options:" + And stdout should contain "--version" + And stdout should contain "--help" + And stdout should contain "Configuration:" + And stdout should contain "--threads" + And stdout should contain "--min-cell-size" + And stdout should contain "--balance" + And stdout should contain "--boundary" + And stdout should contain "--optimizing-cuts" + And stdout should contain "--small-component-size" + And it should exit with an error + + Scenario: osrm-partition - Help, short + When I run "osrm-partition -h" + Then stderr should be empty + And stdout should contain /osrm-partition(.exe)? \[options\]:/ + And stdout should contain "Options:" + And stdout should contain "--version" + And stdout should contain "--help" + And stdout should contain "Configuration:" + And stdout should contain "--threads" + And stdout should contain "--min-cell-size" + And stdout should contain "--balance" + And stdout should contain "--boundary" + And stdout should contain "--optimizing-cuts" + And stdout should contain "--small-component-size" + And it should exit successfully + + Scenario: osrm-partition - Help, long + When I run "osrm-partition --help" + Then stderr should be empty + And stdout should contain /osrm-partition(.exe)? \[options\]:/ + And stdout should contain "Options:" + And stdout should contain "--version" + And stdout should contain "--help" + And stdout should contain "Configuration:" + And stdout should contain "--threads" + And stdout should contain "--min-cell-size" + And stdout should contain "--balance" + And stdout should contain "--boundary" + And stdout should contain "--optimizing-cuts" + And stdout should contain "--small-component-size" + And it should exit successfully diff --git a/features/options/partition/invalid.feature b/features/options/partition/invalid.feature new file mode 100644 index 000000000..fc832d93f --- /dev/null +++ b/features/options/partition/invalid.feature @@ -0,0 +1,20 @@ +@partition @options @invalid +Feature: osrm-partition command line options: invalid options + + Background: + Given the profile "testbot" + And the node map + """ + a b + """ + And the ways + | nodes | + | ab | + And the data has been extracted + + Scenario: osrm-partition - Non-existing option + When I try to run "osrm-partition --fly-me-to-the-moon" + Then stdout should be empty + And stderr should contain "option" + And stderr should contain "fly-me-to-the-moon" + And it should exit with an error diff --git a/features/options/partition/version.feature b/features/options/partition/version.feature new file mode 100644 index 000000000..df99c06e1 --- /dev/null +++ b/features/options/partition/version.feature @@ -0,0 +1,19 @@ +@partition @options @version +Feature: osrm-partition command line options: version + + Background: + Given the profile "testbot" + + Scenario: osrm-partition - Version, short + When I run "osrm-partition --v" + Then stderr should be empty + And stdout should contain 1 line + And stdout should contain /(v\d{1,2}\.\d{1,2}\.\d{1,2}|\w*-\d+-\w+)/ + And it should exit successfully + + Scenario: osrm-partition - Version, long + When I run "osrm-partition --version" + Then stderr should be empty + And stdout should contain 1 line + And stdout should contain /(v\d{1,2}\.\d{1,2}\.\d{1,2}|\w*-\d+-\w+)/ + And it should exit successfully diff --git a/features/step_definitions/data.js b/features/step_definitions/data.js index 49ca6d7f1..fe954335e 100644 --- a/features/step_definitions/data.js +++ b/features/step_definitions/data.js @@ -23,6 +23,16 @@ module.exports = function () { callback(); }); + this.Given(/^the partition extra arguments "(.*?)"$/, (args, callback) => { + this.partitionArgs = this.expandOptions(args); + callback(); + }); + + this.Given(/^the customize extra arguments "(.*?)"$/, (args, callback) => { + this.customizeArgs = this.expandOptions(args); + callback(); + }); + this.Given(/^a grid size of ([0-9.]+) meters$/, (meters, callback) => { this.setGridSize(meters); callback(); @@ -259,12 +269,12 @@ module.exports = function () { this.writeAndLinkOSM(callback); }); - this.Given(/^the data has been extracted$/, (callback) => { + this.Given(/^the data has been (extract|contract)ed$/, (step, callback) => { this.reprocess(callback); }); - this.Given(/^the data has been contracted$/, (callback) => { - this.reprocess(callback); + this.Given(/^the data has been (partition|customiz)ed$/, (step, callback) => { + this.reprocessMLD(callback); }); this.Given(/^osrm\-routed is stopped$/, (callback) => { diff --git a/features/step_definitions/options.js b/features/step_definitions/options.js index 948f89208..abf3b6cdf 100644 --- a/features/step_definitions/options.js +++ b/features/step_definitions/options.js @@ -25,32 +25,16 @@ module.exports = function () { this.runAndSafeOutput('osrm-routed', options, callback); }); - this.When(/^I run "osrm\-extract\s?(.*?)"$/, (options, callback) => { - const stamp = this.processedCacheFile + '.extract'; - this.runAndSafeOutput('osrm-extract', options, (err) => { + this.When(/^I run "osrm\-(extract|contract|partition|customize)\s?(.*?)"$/, (binary, options, callback) => { + const stamp = this.processedCacheFile + '.stamp_' + binary; + this.runAndSafeOutput('osrm-' + binary, options, (err) => { if (err) return callback(err); fs.writeFile(stamp, 'ok', callback); }); }); - this.When(/^I run "osrm\-contract\s?(.*?)"$/, (options, callback) => { - const stamp = this.processedCacheFile + '.contract'; - this.runAndSafeOutput('osrm-contract', options, (err) => { - if (err) return callback(err); - fs.writeFile(stamp, 'ok', 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 try to run "(osrm\-[a-z]+)\s?(.*?)"$/, (binary, options, callback) => { + this.runAndSafeOutput(binary, options, () => { callback(); }); }); this.When(/^I run "osrm\-datastore\s?(.*?)"(?: with input "([^"]*)")?$/, (options, input, callback) => { diff --git a/features/support/data.js b/features/support/data.js index c01cda3b7..13cdebbc0 100644 --- a/features/support/data.js +++ b/features/support/data.js @@ -179,7 +179,7 @@ module.exports = function () { }; this.extractData = (p, callback) => { - let stamp = p.processedCacheFile + '.extract'; + let stamp = p.processedCacheFile + '.stamp_extract'; fs.exists(stamp, (exists) => { if (exists) return callback(); @@ -193,7 +193,7 @@ module.exports = function () { }; this.contractData = (p, callback) => { - let stamp = p.processedCacheFile + '.contract'; + let stamp = p.processedCacheFile + '.stamp_contract'; fs.exists(stamp, (exists) => { if (exists) return callback(); @@ -206,10 +206,39 @@ module.exports = function () { }); }; + this.partitionData = (p, callback) => { + let stamp = p.processedCacheFile + '.stamp_partition'; + fs.exists(stamp, (exists) => { + if (exists) return callback(); + + this.runBin('osrm-partition', util.format('%s %s', p.partitionArgs, p.processedCacheFile), p.environment, (err) => { + if (err) { + return callback(new Error(util.format('osrm-partition %s: %s', errorReason(err), err.cmd))); + } + fs.writeFile(stamp, 'ok', callback); + }); + }); + }; + + this.customizeData = (p, callback) => { + let stamp = p.processedCacheFile + '.stamp_customize'; + fs.exists(stamp, (exists) => { + if (exists) return callback(); + + this.runBin('osrm-customize', util.format('%s %s', p.customizeArgs, p.processedCacheFile), p.environment, (err) => { + if (err) { + return callback(new Error(util.format('osrm-customize %s: %s', errorReason(err), err))); + } + fs.writeFile(stamp, 'ok', callback); + }); + }); + }; + this.extractAndContract = (callback) => { // a shallow copy of scenario parameters to avoid data inconsistency // if a cucumber timeout occurs during deferred jobs let p = {extractArgs: this.extractArgs, contractArgs: this.contractArgs, + partitionArgs: this.partitionArgs, customizeArgs: this.customizeArgs, profileFile: this.profileFile, inputCacheFile: this.inputCacheFile, processedCacheFile: this.processedCacheFile, environment: this.environment}; let queue = d3.queue(1); @@ -218,6 +247,19 @@ module.exports = function () { queue.awaitAll(callback); }; + this.extractPartitionAndCustomize = (callback) => { + // a shallow copy of scenario parameters to avoid data inconsistency + // if a cucumber timeout occurs during deferred jobs + let p = {extractArgs: this.extractArgs, partitionArgs: this.partitionArgs, customizeArgs: this.customizeArgs, + profileFile: this.profileFile, inputCacheFile: this.inputCacheFile, + processedCacheFile: this.processedCacheFile, environment: this.environment}; + let queue = d3.queue(1); + queue.defer(this.extractData.bind(this), p); + queue.defer(this.partitionData.bind(this), p); + queue.defer(this.customizeData.bind(this), p); + queue.awaitAll(callback); + }; + this.writeAndLinkOSM = (callback) => { let queue = d3.queue(1); queue.defer(this.writeOSM.bind(this)); @@ -232,10 +274,19 @@ module.exports = function () { queue.awaitAll(callback); }; + this.reprocessMLD = (callback) => { + let queue = d3.queue(1); + queue.defer(this.writeAndLinkOSM.bind(this)); + queue.defer(this.extractPartitionAndCustomize.bind(this)); + queue.awaitAll(callback); + }; + this.reprocessAndLoadData = (callback) => { let queue = d3.queue(1); queue.defer(this.writeAndLinkOSM.bind(this)); - queue.defer(this.extractAndContract.bind(this)); + queue.defer((this.ROUTING_ALGORITHM === 'MLD' ? + this.extractPartitionAndCustomize : + this.extractAndContract).bind(this)); queue.defer(this.osrmLoader.load.bind(this.osrmLoader), this.processedCacheFile); queue.awaitAll(callback); }; diff --git a/features/support/env.js b/features/support/env.js index 79c8dd862..8e1f8d474 100644 --- a/features/support/env.js +++ b/features/support/env.js @@ -34,12 +34,12 @@ module.exports = function () { this.DEFAULT_LOAD_METHOD = 'datastore'; this.DEFAULT_ORIGIN = [1,1]; 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; this.DEFAULT_GRID_SIZE = 100; // meters - this.ROUTING_ALGORITHM = 'CH'; + // get algorithm name from the command line profile argument + this.ROUTING_ALGORITHM = process.argv[process.argv.indexOf('-p') + 1] === 'mld' ? 'MLD' : 'CH'; this.OSRM_PORT = process.env.OSRM_PORT && parseInt(process.env.OSRM_PORT) || 5000; this.HOST = 'http://127.0.0.1:' + this.OSRM_PORT; diff --git a/features/support/hooks.js b/features/support/hooks.js index b0f6b0b77..f3c7fe10d 100644 --- a/features/support/hooks.js +++ b/features/support/hooks.js @@ -35,6 +35,8 @@ module.exports = function () { this.queryParams = {}; this.extractArgs = ''; this.contractArgs = ''; + this.partitionArgs = ''; + this.customizeArgs = ''; this.environment = Object.assign(this.DEFAULT_ENVIRONMENT); this.resetOSM(); diff --git a/features/testbot/loop.feature b/features/testbot/loop.feature index 41a6bb4c0..985c8ba6a 100644 --- a/features/testbot/loop.feature +++ b/features/testbot/loop.feature @@ -4,6 +4,7 @@ Feature: Avoid weird loops caused by rounding errors Background: Given the profile "testbot" + @via Scenario: Weird sidestreet loops Given the node map """ @@ -72,7 +73,7 @@ Feature: Avoid weird loops caused by rounding errors | from | to | route | | x | y | abc,abc | - @412 + @412 @via Scenario: Avoid weird loops 3 And the node map """ diff --git a/features/testbot/weight.feature b/features/testbot/weight.feature index 7e9c113ea..afe3f5e15 100644 --- a/features/testbot/weight.feature +++ b/features/testbot/weight.feature @@ -240,6 +240,7 @@ Feature: Weight tests | e,d | ,, | 40m +-.1 | 4.009,1.11,0 | 189.9s,100s,0s | | d,e | ,, | 40m +-.1 | 2.21,1.11,0 | 10.1s,100s,0s | + @traffic @speed Scenario: Step weights -- segment_function with speed and turn updates Given the profile file "testbot" extended with """ @@ -286,6 +287,7 @@ Feature: Weight tests | a,e | ,, | 60.1m | 68.7,10,0 | 38.5s,11s,0s | | d,e | ,, | 39.9m | 10,10,0 | 11s,11s,0s | + @traffic @speed Scenario: Step weights -- segment_function with speed and turn updates with fallback to durations Given the profile file "testbot" extended with """ diff --git a/package.json b/package.json index 363a4dfe5..84547068d 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ }, "scripts": { "lint": "eslint -c ./.eslintrc features/step_definitions/ features/support/", - "test": "npm run lint && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify", + "test": "npm run lint && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify && node ./node_modules/cucumber/bin/cucumber.js features/ -p mld", "clean-test": "rm -rf test/cache", "cucumber": "./node_modules/cucumber/bin/cucumber.js", "build-api-docs": "./scripts/build_api_docs.sh" diff --git a/src/tools/customize.cpp b/src/tools/customize.cpp index ee3befca4..f675f309f 100644 --- a/src/tools/customize.cpp +++ b/src/tools/customize.cpp @@ -107,7 +107,7 @@ parseArguments(int argc, char *argv[], customizer::CustomizationConfig &customiz if (!option_variables.count("input")) { std::cout << visible_options; - return return_code::exit; + return return_code::fail; } return return_code::ok; diff --git a/src/tools/partition.cpp b/src/tools/partition.cpp index 5f3fa74fd..b3c80d05f 100644 --- a/src/tools/partition.cpp +++ b/src/tools/partition.cpp @@ -116,7 +116,7 @@ return_code parseArguments(int argc, char *argv[], partition::PartitionConfig &p if (!option_variables.count("input")) { std::cout << visible_options; - return return_code::exit; + return return_code::fail; } return return_code::ok;