From ec56478a3c5d7b6ee7fec9e1b35d64e5bc2325c9 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Sun, 16 Dec 2012 13:36:47 +0100 Subject: [PATCH] cucumber cleanup, removed unused code --- features/bicycle/access.feature | 2 +- features/bicycle/area.feature | 2 +- features/bicycle/barrier.feature | 2 +- features/bicycle/cycleway.feature | 2 +- features/bicycle/destination.feature | 2 +- features/bicycle/ferry.feature | 2 +- features/bicycle/maxspeed.feature | 2 +- features/bicycle/names.feature | 2 +- features/bicycle/oneway.feature | 2 +- features/bicycle/restrictions.feature | 2 +- features/bicycle/stop_area.feature | 2 +- features/bicycle/train.feature | 2 +- features/bicycle/way.feature | 4 +- features/car/access.feature | 2 +- features/car/barrier.feature | 2 +- features/car/destination.feature | 2 +- features/car/ferry.feature | 2 +- features/car/maxspeed.feature | 2 +- features/car/names.feature | 2 +- features/car/oneway.feature | 2 +- features/car/restrictions.feature | 2 +- features/car/way.feature | 2 +- features/foot/oneway.feature | 2 +- features/foot/way.feature | 2 +- features/investigate/weird.feature | 2 +- features/step_definitions/data.rb | 4 +- features/step_definitions/errors.rb | 14 -- features/step_definitions/processing.rb | 74 ---------- features/step_definitions/requests.rb | 22 +++ features/step_definitions/routability.rb | 40 ++++++ features/step_definitions/routing.rb | 176 ----------------------- features/stress/launch.feature | 32 ++++- features/support/config.rb | 14 +- features/support/data.rb | 11 +- features/support/hash.rb | 8 +- features/support/log.rb | 4 +- features/support/osm_parser.rb | 23 +++ features/support/request.rb | 17 --- features/support/route.rb | 17 +++ features/testbot/bad.feature | 2 +- features/testbot/basic.feature | 2 +- features/testbot/bearing.feature | 2 +- features/testbot/distance.feature | 2 +- features/testbot/ferry.feature | 2 +- features/testbot/origin.feature | 2 +- features/testbot/penalty.feature | 2 +- features/testbot/snap.feature | 6 +- features/testbot/time.feature | 2 +- features/testbot/turns.feature | 2 +- features/testbot/utf.feature | 2 +- features/testbot/weight.feature | 2 +- 51 files changed, 187 insertions(+), 349 deletions(-) delete mode 100644 features/step_definitions/errors.rb delete mode 100644 features/step_definitions/processing.rb create mode 100644 features/step_definitions/routability.rb create mode 100644 features/support/osm_parser.rb delete mode 100644 features/support/request.rb diff --git a/features/bicycle/access.feature b/features/bicycle/access.feature index 6ea15b9ec..149a2743c 100644 --- a/features/bicycle/access.feature +++ b/features/bicycle/access.feature @@ -3,7 +3,7 @@ Feature: Bike - Restricted access Reference: http://wiki.openstreetmap.org/wiki/Key:access Background: - Given the speedprofile "bicycle" + Given the profile "bicycle" Scenario: Bike - Access tag hierachy on ways Then routability should be diff --git a/features/bicycle/area.feature b/features/bicycle/area.feature index 267e57539..0be8235d8 100644 --- a/features/bicycle/area.feature +++ b/features/bicycle/area.feature @@ -2,7 +2,7 @@ Feature: Bike - Squares and other areas Background: - Given the speedprofile "bicycle" + Given the profile "bicycle" @square Scenario: Bike - Route along edge of a squares diff --git a/features/bicycle/barrier.feature b/features/bicycle/barrier.feature index dd75dd2b6..5aa958824 100644 --- a/features/bicycle/barrier.feature +++ b/features/bicycle/barrier.feature @@ -2,7 +2,7 @@ Feature: Barriers Background: - Given the speedprofile "bicycle" + Given the profile "bicycle" Scenario: Bike - Barriers Then routability should be diff --git a/features/bicycle/cycleway.feature b/features/bicycle/cycleway.feature index 89aceb85e..bf42563ff 100644 --- a/features/bicycle/cycleway.feature +++ b/features/bicycle/cycleway.feature @@ -3,7 +3,7 @@ Feature: Bike - Cycle tracks/lanes Reference: http://wiki.openstreetmap.org/wiki/Key:cycleway Background: - Given the speedprofile "bicycle" + Given the profile "bicycle" Scenario: Bike - Cycle tracks/lanes should enable biking Then routability should be diff --git a/features/bicycle/destination.feature b/features/bicycle/destination.feature index 7d3220f64..b3f8b5b37 100644 --- a/features/bicycle/destination.feature +++ b/features/bicycle/destination.feature @@ -2,7 +2,7 @@ Feature: Bike - Destination only, no passing through Background: - Given the speedprofile "bicycle" + Given the profile "bicycle" Scenario: Bike - Destination only street Given the node map diff --git a/features/bicycle/ferry.feature b/features/bicycle/ferry.feature index 1223da6c6..762774cf1 100644 --- a/features/bicycle/ferry.feature +++ b/features/bicycle/ferry.feature @@ -2,7 +2,7 @@ Feature: Bike - Handle ferry routes Background: - Given the speedprofile "bicycle" + Given the profile "bicycle" Scenario: Bike - Ferry route Given the node map diff --git a/features/bicycle/maxspeed.feature b/features/bicycle/maxspeed.feature index 801c7c9c4..30d82b7e8 100644 --- a/features/bicycle/maxspeed.feature +++ b/features/bicycle/maxspeed.feature @@ -2,7 +2,7 @@ Feature: Bike - Max speed restrictions Background: Use specific speeds - Given the speedprofile "bicycle" + Given the profile "bicycle" Scenario: Bike - Respect maxspeeds when lower that way type speed Given the node map diff --git a/features/bicycle/names.feature b/features/bicycle/names.feature index 42273a9be..d1912472f 100644 --- a/features/bicycle/names.feature +++ b/features/bicycle/names.feature @@ -2,7 +2,7 @@ Feature: Bike - Street names in instructions Background: - Given the speedprofile "bicycle" + Given the profile "bicycle" Scenario: Bike - A named street Given the node map diff --git a/features/bicycle/oneway.feature b/features/bicycle/oneway.feature index 0b1d3caf9..4e6cb4f2d 100644 --- a/features/bicycle/oneway.feature +++ b/features/bicycle/oneway.feature @@ -3,7 +3,7 @@ Feature: Bike - Oneway streets Handle oneways streets, as defined at http://wiki.openstreetmap.org/wiki/OSM_tags_for_routing Background: - Given the speedprofile "bicycle" + Given the profile "bicycle" Scenario: Bike - Simple oneway Then routability should be diff --git a/features/bicycle/restrictions.feature b/features/bicycle/restrictions.feature index 073233114..736c939aa 100644 --- a/features/bicycle/restrictions.feature +++ b/features/bicycle/restrictions.feature @@ -4,7 +4,7 @@ Feature: Bike - Turn restrictions Note that if u-turns are allowed, turn restrictions can lead to suprising, but correct, routes. Background: Use car routing - Given the speedprofile "bicycle" + Given the profile "bicycle" @no_turning Scenario: Bike - No left turn diff --git a/features/bicycle/stop_area.feature b/features/bicycle/stop_area.feature index c351be569..7113808b0 100644 --- a/features/bicycle/stop_area.feature +++ b/features/bicycle/stop_area.feature @@ -4,7 +4,7 @@ Platforms and railway/bus lines are connected using a relation rather that a way http://wiki.openstreetmap.org/wiki/Tag:public_transport%3Dstop_area Background: - Given the speedprofile "bicycle" + Given the profile "bicycle" Scenario: Bike - Platforms tagged using public_transport Then routability should be diff --git a/features/bicycle/train.feature b/features/bicycle/train.feature index dd67e08db..1b5699f16 100644 --- a/features/bicycle/train.feature +++ b/features/bicycle/train.feature @@ -3,7 +3,7 @@ Feature: Bike - Handle ferry routes Bringing bikes on trains and subways Background: - Given the speedprofile "bicycle" + Given the profile "bicycle" Scenario: Bike - Bringing bikes on trains Then routability should be diff --git a/features/bicycle/way.feature b/features/bicycle/way.feature index 9586c8e20..ca157bd25 100644 --- a/features/bicycle/way.feature +++ b/features/bicycle/way.feature @@ -2,11 +2,11 @@ Feature: Bike - Accessability of different way types Background: - Given the speedprofile "bicycle" + Given the profile "bicycle" Scenario: Bike - Basic access Bikes are allowed on footways etc because you can pull your bike at a lower speed. - Given the speedprofile "bicycle" + Given the profile "bicycle" Then routability should be | highway | forw | | (nil) | | diff --git a/features/car/access.feature b/features/car/access.feature index a2aca3b57..02b68af1e 100644 --- a/features/car/access.feature +++ b/features/car/access.feature @@ -3,7 +3,7 @@ Feature: Car - Restricted access Reference: http://wiki.openstreetmap.org/wiki/Key:access Background: - Given the speedprofile "car" + Given the profile "car" Scenario: Car - Access tag hierachy on ways Then routability should be diff --git a/features/car/barrier.feature b/features/car/barrier.feature index 1ae343237..9d37d354a 100644 --- a/features/car/barrier.feature +++ b/features/car/barrier.feature @@ -2,7 +2,7 @@ Feature: Car - Barriers Background: - Given the speedprofile "car" + Given the profile "car" Scenario: Car - Barriers Then routability should be diff --git a/features/car/destination.feature b/features/car/destination.feature index 35314369a..43059e1e2 100644 --- a/features/car/destination.feature +++ b/features/car/destination.feature @@ -2,7 +2,7 @@ Feature: Car - Destination only, no passing through Background: - Given the speedprofile "car" + Given the profile "car" Scenario: Car - Destination only street Given the node map diff --git a/features/car/ferry.feature b/features/car/ferry.feature index 4b1caf583..3182c7533 100644 --- a/features/car/ferry.feature +++ b/features/car/ferry.feature @@ -2,7 +2,7 @@ Feature: Car - Handle ferry routes Background: - Given the speedprofile "car" + Given the profile "car" Scenario: Car - Use a ferry route Given the node map diff --git a/features/car/maxspeed.feature b/features/car/maxspeed.feature index 52d920ec4..cc31c6c13 100644 --- a/features/car/maxspeed.feature +++ b/features/car/maxspeed.feature @@ -2,7 +2,7 @@ Feature: Car - Max speed restrictions Background: Use specific speeds - Given the speedprofile "car" + Given the profile "car" Given a grid size of 1000 meters Scenario: Car - Respect maxspeeds when lower that way type speed diff --git a/features/car/names.feature b/features/car/names.feature index 225e0cce2..d7d98b7e4 100644 --- a/features/car/names.feature +++ b/features/car/names.feature @@ -2,7 +2,7 @@ Feature: Car - Street names in instructions Background: - Given the speedprofile "car" + Given the profile "car" Scenario: Car - A named street Given the node map diff --git a/features/car/oneway.feature b/features/car/oneway.feature index 99963680e..0d906c06c 100644 --- a/features/car/oneway.feature +++ b/features/car/oneway.feature @@ -3,7 +3,7 @@ Feature: Car - Oneway streets Handle oneways streets, as defined at http://wiki.openstreetmap.org/wiki/OSM_tags_for_routing Background: - Given the speedprofile "car" + Given the profile "car" Scenario: Car - Simple oneway Then routability should be diff --git a/features/car/restrictions.feature b/features/car/restrictions.feature index 2bc00f4a9..1ee527395 100644 --- a/features/car/restrictions.feature +++ b/features/car/restrictions.feature @@ -4,7 +4,7 @@ Feature: Car - Turn restrictions Note that if u-turns are allowed, turn restrictions can lead to suprising, but correct, routes. Background: Use car routing - Given the speedprofile "car" + Given the profile "car" @no_turning Scenario: Car - No left turn diff --git a/features/car/way.feature b/features/car/way.feature index 873dea943..8ca62a56c 100644 --- a/features/car/way.feature +++ b/features/car/way.feature @@ -2,7 +2,7 @@ Feature: Car - Accessability of different way types Background: - Given the speedprofile "car" + Given the profile "car" Scenario: Car - Basic access Then routability should be diff --git a/features/foot/oneway.feature b/features/foot/oneway.feature index 3eb82b4a4..e1c96e3ac 100644 --- a/features/foot/oneway.feature +++ b/features/foot/oneway.feature @@ -3,7 +3,7 @@ Feature: Foot - Oneway streets Handle oneways streets, as defined at http://wiki.openstreetmap.org/wiki/OSM_tags_for_routing Background: - Given the speedprofile "foot" + Given the profile "foot" Scenario: Foot - Walking should not be affected by oneways Then routability should be diff --git a/features/foot/way.feature b/features/foot/way.feature index 19b728ebd..e18d9f871 100644 --- a/features/foot/way.feature +++ b/features/foot/way.feature @@ -2,7 +2,7 @@ Feature: Foot - Accessability of different way types Background: - Given the speedprofile "foot" + Given the profile "foot" Scenario: Foot - Basic access Then routability should be diff --git a/features/investigate/weird.feature b/features/investigate/weird.feature index 7c4cbcfd7..f84a07592 100644 --- a/features/investigate/weird.feature +++ b/features/investigate/weird.feature @@ -2,7 +2,7 @@ Feature: Weird routings discovered Background: - Given the speedprofile "testbot" + Given the profile "testbot" Scenario: Routing on a oneway roundabout Given the node map diff --git a/features/step_definitions/data.rb b/features/step_definitions/data.rb index f4e5de00e..fc34105fb 100644 --- a/features/step_definitions/data.rb +++ b/features/step_definitions/data.rb @@ -1,5 +1,5 @@ -Given /^the speedprofile "([^"]*)"$/ do |profile| - read_speedprofile profile +Given /^the profile "([^"]*)"$/ do |profile| + set_profile profile end Given /^a grid size of (\d+) meters$/ do |meters| diff --git a/features/step_definitions/errors.rb b/features/step_definitions/errors.rb deleted file mode 100644 index 398d81d45..000000000 --- a/features/step_definitions/errors.rb +++ /dev/null @@ -1,14 +0,0 @@ - -When /^I preprocess data$/ do - begin - reprocess - rescue OSRMError => e - @process_error = e - end -end - -Then /^preparing should return code (\d+)$/ do |code| - @process_error.class.should == OSRMError - @process_error.process.should == 'osrm-prepare' - @process_error.code.to_i.should == code.to_i -end diff --git a/features/step_definitions/processing.rb b/features/step_definitions/processing.rb deleted file mode 100644 index 29b865e39..000000000 --- a/features/step_definitions/processing.rb +++ /dev/null @@ -1,74 +0,0 @@ -require 'OSM/StreamParser' - -class OSMTestParserCallbacks < OSM::Callbacks - @@locations = nil - - def self.locations - if @@locations - @@locations - else - #parse the test file, so we can later reference nodes and ways by name in tests - @@locations = {} - file = 'test/data/test.osm' - callbacks = OSMTestParserCallbacks.new - parser = OSM::StreamParser.new(:filename => file, :callbacks => callbacks) - parser.parse - puts @@locations - end - end - - def node(node) - @@locations[node.name] = [node.lat,node.lon] - end -end - - -Given /^the OSM file contains$/ do |string| - file = 'data/test.osm' - File.open( file, 'w') {|f| f.write(string) } - - #convert from .osm to .osm.pbf, which is the format osrm reads - system "osmosis --read-xml data/test.osm --write-pbf data/test.osm.pbf omitmetadata=true" -end - -Given /^the speedprofile contains$/ do |string| - File.open( 'speedprofile.ini', 'w') {|f| f.write(string) } -end - - - -Given /^the data file "([^"]*)" is present$/ do |file| - File.exists?(file).should == true -end - -When /^I run the extractor with "([^"]*)"$/ do |cmd| - @response = `#{cmd}` - #Dir.chdir @test_folder do - # @response = IO.popen([cmd, :err=>[:child, :out]]) { |ls_io| ls_result_with_error = ls_io.read } - #end -end - -When /^I run the preprocessor with "([^"]*)"$/ do |cmd| - @response = `#{cmd}` -end - -Given /^the preprocessed files for "([^"]*)" are present and up to date$/ do |area| - File.exists?("#{area}.osrm").should == true - File.exists?("#{area}.osrm.names").should == true - File.exists?("#{area}.osrm.restrictions").should == true - File.exists?("#{area}.osrm.hsgr").should == true - File.exists?("#{area}.osrm.nodes").should == true - File.exists?("#{area}.osrm.edges").should == true - File.exists?("#{area}.osrm.ramIndex").should == true - File.exists?("#{area}.osrm.fileIndex").should == true - File.exists?("#{area}.osrm.tiemstamp").should == true -end - -Then /^I should see the file "([^"]*)"$/ do |file| - File.exists?(file).should == true -end - -When /^preprocessed files for "([^"]*)" has been removed$/ do |file| - FileUtils.rm_r Dir["#{file}.*"], :secure => true -end - diff --git a/features/step_definitions/requests.rb b/features/step_definitions/requests.rb index 6b8045d36..c546d13d4 100644 --- a/features/step_definitions/requests.rb +++ b/features/step_definitions/requests.rb @@ -21,3 +21,25 @@ Then /^response should be well-formed$/ do @json['transactionId'].class.should == String end +Then /^response should be a well-formed route$/ do + step "response should be well-formed" + @json['status_message'].class.should == String + @json['route_summary'].class.should == Hash + @json['route_geometry'].class.should == String + @json['route_instructions'].class.should == Array + @json['via_points'].class.should == Array +end + +When /^I preprocess data$/ do + begin + reprocess + rescue OSRMError => e + @process_error = e + end +end + +Then /^preparing should return code (\d+)$/ do |code| + @process_error.class.should == OSRMError + @process_error.process.should == 'osrm-prepare' + @process_error.code.to_i.should == code.to_i +end diff --git a/features/step_definitions/routability.rb b/features/step_definitions/routability.rb new file mode 100644 index 000000000..d949d01b9 --- /dev/null +++ b/features/step_definitions/routability.rb @@ -0,0 +1,40 @@ +Then /^routability should be$/ do |table| + build_ways_from_table table + reprocess + actual = [] + if table.headers&["forw","backw","bothw"] == [] + raise "*** routability tabel must contain either 'forw', 'backw' or 'bothw' column" + end + OSRMLauncher.new do + table.hashes.each_with_index do |row,i| + got = row.dup + attempts = [] + ['forw','backw','bothw'].each do |direction| + if table.headers.include? direction + if direction == 'forw' || direction == 'bothw' + response = request_route("#{ORIGIN[1]},#{ORIGIN[0]+(1+WAY_SPACING*i)*@zoom}","#{ORIGIN[1]},#{ORIGIN[0]+(3+WAY_SPACING*i)*@zoom}") + elsif direction == 'backw' || direction == 'bothw' + response = request_route("#{ORIGIN[1]},#{ORIGIN[0]+(3+WAY_SPACING*i)*@zoom}","#{ORIGIN[1]},#{ORIGIN[0]+(1+WAY_SPACING*i)*@zoom}") + end + got[direction] = route_status response + json = JSON.parse(response.body) + if got[direction].empty? == false + route = way_list json['route_instructions'] + if route != "w#{i}" + got[direction] = "testing w#{i}, but got #{route}!?" + elsif row[direction] =~ /\d+s/ + time = json['route_summary']['total_time'] + got[direction] = "#{time}s" + end + end + if got[direction] != row[direction] + attempts << { :attempt => direction, :query => @query, :response => response } + end + end + end + log_fail row,got,attempts if got != row + actual << got + end + end + table.routing_diff! actual +end diff --git a/features/step_definitions/routing.rb b/features/step_definitions/routing.rb index 8ed4e6739..32e6f60e5 100644 --- a/features/step_definitions/routing.rb +++ b/features/step_definitions/routing.rb @@ -1,179 +1,3 @@ -When /^I request a route from ([^"]+) to ([^"]+)$/ do |a,b| - @response = request_route a,b - #puts @response.body - #@response -end - -When /^I request a route from "([^"]*)" to "([^"]*)"$/ do |a,b| - locations = OSMTestParserCallbacks.locations - raise "Locations hash is empty. To reference nodes by name, please preprocess the test file earlier in the test." unless locations - raise "Unknown node: #{a}" unless locations[a] - raise "Unknown node: #{b}" unless locations[b] - @response = request_route "#{locations[a][0]},#{locations[a][1]}", "#{locations[b][0]},#{locations[b][1]}" -end - -Then /^response should be a well-formed route$/ do - step "response should be well-formed" - @json['status_message'].class.should == String - @json['route_summary'].class.should == Hash - @json['route_geometry'].class.should == String - @json['route_instructions'].class.should == Array - @json['via_points'].class.should == Array -end - -Then /^a route should be found$/ do - @json['status'].should == 0 - @json['status_message'].should == "Found route between points" -end - -Then /^no route should be found$/ do - @json['status'].should == 207 - @json['status_message'].should == "Cannot find route between points" -end - -Then /^I should get a valid response$/ do - step "I should get a response" - step "response should be valid JSON" - step "response should be a well-formed route" - #step "no error should be reported in terminal" -end - -Then /^I should get a route$/ do - step "I should get a valid response" - step "a route should be found" - #puts @response.body -end - -Then /^I should not get a route$/ do - step "I should get a valid response" - step "no route should be found" -end - -Then /^the route should start at "([^']*)"$/ do |name| - @json['route_summary']['start_point'].should == name -end - -Then /^the route should end at "([^']*)"$/ do |name| - @json['route_summary']['end_point'].should == name -end - -Then /^distance should be between (\d+) and (\d+)$/ do |min,max| - @json['route_summary']['total_distance'].to_i.should >= min.to_i - @json['route_summary']['total_distance'].to_i.should <= max.to_i -end - -Then /^the distance should be close to (\d+)m$/ do |d| - @json['route_summary']['total_distance'].to_i.should >= d.to_i*0.95 - @json['route_summary']['total_distance'].to_i.should <= d.to_i/0.95 -end - -Then /^number of instructions should be (\d+)$/ do |n| - @json['route_instructions'].size.should == n -end - -Then /^there should be 1 turn$/ do - step 'there should be 1 turns' -end - -Then /^there should be (\d+) turns$/ do |n| - @json['route_instructions'].map {|t| t.first}.select {|t| t =~ /^Turn/ }.size.should == n.to_i -end - -Then /^there should be more than (\d+) turn$/ do |n| - @json['route_instructions'].map {|t| t.first}.select {|t| t =~ /^Turn/ }.size.should > n.to_i -end - -Then /^there should not be any turns$/ do - (@json['route_instructions'].size-1).should == 0 -end - -def sanitize_route route - route.split(',').map{|w| w.strip}.reject(&:empty?).join(', ') -end - -def computed_route - @json['route_instructions'].map { |r| r[1] }.reject(&:empty?).join(', ') -end - -Then /^the route should follow "([^"]*)"$/ do |route| - sanitize_route(route).should == computed_route -end - -Then /^the route should not follow "([^"]*)"$/ do |route| - sanitize_route(route).should_not == computed_route -end - -Then /^the route should include "([^"]*)"$/ do |route| - sanitize_route(route).should =~ /#{computed_route}/ -end - -Then /^the route should not include "([^"]*)"$/ do |route| - sanitize_route(route).should_not =~ /#{computed_route}/ -end - -Then /^the route should stay on "([^"]*)"$/ do |way| - step "the route should start at \"#{way}\"" - step "the route should end at \"#{way}\"" - step "the route should follow \"#{way}\"" - step "there should not be any turns" -end - -When /^I route between "([^"]*)" and "([^"]*)"$/ do |from,to| - reprocess - Dir.chdir 'test' do - from_node = name_node_hash[from] - to_node = name_node_hash[to] - a = "#{from_node.lon},#{from_node.lat}" - b = "#{to_node.lon},#{to_node.lat}" - @route = parse_response( request_route(a,b) ) - end -end - -Then /^"([^"]*)" should be returned$/ do |route| - @route.should == route.split(',').join(',') -end - -Then /^routability should be$/ do |table| - build_ways_from_table table - reprocess - actual = [] - if table.headers&["forw","backw","bothw"] == [] - raise "*** routability tabel must contain either 'forw', 'backw' or 'bothw' column" - end - OSRMLauncher.new do - table.hashes.each_with_index do |row,i| - got = row.dup - attempts = [] - ['forw','backw','bothw'].each do |direction| - if table.headers.include? direction - if direction == 'forw' || direction == 'bothw' - response = request_route("#{ORIGIN[1]},#{ORIGIN[0]+(1+WAY_SPACING*i)*@zoom}","#{ORIGIN[1]},#{ORIGIN[0]+(3+WAY_SPACING*i)*@zoom}") - elsif direction == 'backw' || direction == 'bothw' - response = request_route("#{ORIGIN[1]},#{ORIGIN[0]+(3+WAY_SPACING*i)*@zoom}","#{ORIGIN[1]},#{ORIGIN[0]+(1+WAY_SPACING*i)*@zoom}") - end - got[direction] = route_status response - json = JSON.parse(response.body) - if got[direction].empty? == false - route = way_list json['route_instructions'] - if route != "w#{i}" - got[direction] = "testing w#{i}, but got #{route}!?" - elsif row[direction] =~ /\d+s/ - time = json['route_summary']['total_time'] - got[direction] = "#{time}s" - end - end - if got[direction] != row[direction] - attempts << { :attempt => direction, :query => @query, :response => response } - end - end - end - log_fail row,got,attempts if got != row - actual << got - end - end - table.routing_diff! actual -end - When /^I route I should get$/ do |table| reprocess actual = [] diff --git a/features/stress/launch.feature b/features/stress/launch.feature index 752a405be..a8d688fcd 100644 --- a/features/stress/launch.feature +++ b/features/stress/launch.feature @@ -1,10 +1,34 @@ -@stress @launch +@stress Feature: Launching and shutting down Background: - Given the speedprofile "testbot" + Given the profile "testbot" - Scenario: Repeated launch and shutdown + Scenario: Stress - 10km routing + #osrm-routed hangs very often + Given a grid size of 10000 meters + Given the node map + | h | a | b | + | g | x | c | + | f | e | d | + + And the ways + | nodes | highway | + | xa | primary | + | xb | primary | + | xc | primary | + | xd | primary | + | xe | primary | + | xf | primary | + | xg | primary | + | xh | primary | + + When I route 100 times I should get + | from | to | route | + | x | h | xh | + + Scenario: Stress - 10km routing + #osrm-routed hangs sometimes Given a grid size of 10000 meters Given the node map | h | a | b | @@ -31,4 +55,4 @@ Feature: Launching and shutting down | x | e | xe | | x | f | xf | | x | g | xg | - | x | h | xh | \ No newline at end of file + | x | h | xh | diff --git a/features/support/config.rb b/features/support/config.rb index 24b76cb7a..63350d511 100644 --- a/features/support/config.rb +++ b/features/support/config.rb @@ -1,14 +1,14 @@ -def speedprofile - @speedprofile ||= reset_speedprofile +def profile + @profile ||= reset_profile end -def reset_speedprofile - @speedprofile = nil - read_speedprofile DEFAULT_SPEEDPROFILE +def reset_profile + @profile = nil + set_profile DEFAULT_SPEEDPROFILE end -def read_speedprofile profile - @speedprofile = profile +def set_profile profile + @profile = profile end def write_server_ini diff --git a/features/support/data.rb b/features/support/data.rb index 2c31af83a..d45ea47e3 100644 --- a/features/support/data.rb +++ b/features/support/data.rb @@ -116,7 +116,7 @@ def reset_data #clear_log #clear_data_files end - reset_speedprofile + reset_profile reset_osm @fingerprint = nil end @@ -131,10 +131,6 @@ def reset_osm name_way_hash.clear @osm_str = nil @osm_hash = nil - - ##ID -1 causes trouble, so add a few nodes to avoid it - #node = OSM::Node.new nil, OSM_USER, OSM_TIMESTAMP, 0,0 - #node = OSM::Node.new nil, OSM_USER, OSM_TIMESTAMP, 0,0 @osm_id = 0 end @@ -180,7 +176,6 @@ def convert_osm_to_pbf unless File.exist?("#{@osm_file}.osm.pbf") log_preprocess_info log "== Converting #{@osm_file}.osm to protobuffer format...", :preprocess - #redirect stdout and stderr to a log file avoid output in the cucumber console unless system "osmosis --read-xml #{@osm_file}.osm --write-pbf #{@osm_file}.osm.pbf omitmetadata=true 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE}" raise "Failed to convert to proto buffer format. Please see #{hash}.log for more info." end @@ -210,7 +205,7 @@ def reprocess unless extracted? log_preprocess_info log "== Extracting #{@osm_file}.osm...", :preprocess - unless system "../osrm-extract #{@osm_file}.osm.pbf 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE} ../profiles/#{@speedprofile}.lua" + unless system "../osrm-extract #{@osm_file}.osm.pbf 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE} ../profiles/#{@profile}.lua" log "*** Exited with code #{$?.exitstatus}.", :preprocess raise OSRMError.new 'osrm-extract', $?.exitstatus, "*** osrm-extract exited with code #{$?.exitstatus}. The file preprocess.log might contain more info." end @@ -219,7 +214,7 @@ def reprocess unless prepared? log_preprocess_info log "== Preparing #{@osm_file}.osm...", :preprocess - unless system "../osrm-prepare #{@osm_file}.osrm #{@osm_file}.osrm.restrictions 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE} ../profiles/#{@speedprofile}.lua" + unless system "../osrm-prepare #{@osm_file}.osrm #{@osm_file}.osrm.restrictions 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE} ../profiles/#{@profile}.lua" log "*** Exited with code #{$?.exitstatus}.", :preprocess raise OSRMError.new 'osrm-prepare', $?.exitstatus, "*** osrm-prepare exited with code #{$?.exitstatus}. The file preprocess.log might contain more info." end diff --git a/features/support/hash.rb b/features/support/hash.rb index 8dc696a63..46a32d67c 100644 --- a/features/support/hash.rb +++ b/features/support/hash.rb @@ -11,8 +11,8 @@ def hash_of_file path return hash.hexdigest end -def speedprofile_hash - @speedprofile_hash ||= hash_of_file "../profiles/#{@speedprofile}.lua" +def profile_hash + @profile_hash ||= hash_of_file "../profiles/#{@profile}.lua" end def osm_hash @@ -31,8 +31,8 @@ def bin_routed_hash @bin_routed_hash ||= hash_of_file '../osrm-routed' end -#combine state of data, speedprofile and binaries into a hash that identifies the exact test scenario +#combine state of data, profile and binaries into a hash that identifies the exact test scenario def fingerprint - @fingerprint ||= Digest::SHA1.hexdigest "#{bin_extract_hash}-#{bin_prepare_hash}-#{bin_routed_hash}-#{speedprofile_hash}-#{osm_hash}" + @fingerprint ||= Digest::SHA1.hexdigest "#{bin_extract_hash}-#{bin_prepare_hash}-#{bin_routed_hash}-#{profile_hash}-#{osm_hash}" end diff --git a/features/support/log.rb b/features/support/log.rb index f0c9c1938..7aed85029 100644 --- a/features/support/log.rb +++ b/features/support/log.rb @@ -14,7 +14,7 @@ def log_scenario_fail_info log "Failed scenario: #{@scenario_title}" log "Time: #{@scenario_time}" log "Fingerprint: #{@fingerprint}" - log "Profile: #{@speedprofile}" + log "Profile: #{@profile}" log log '```xml' #so output can be posted directly to github comment fields log osm_str.strip @@ -51,7 +51,7 @@ def log_preprocess_info log '```', :preprocess log '', :preprocess log "== Profile:", :preprocess - log @speedprofile, :preprocess + log @profile, :preprocess log '', :preprocess @has_logged_preprocess_info = true end diff --git a/features/support/osm_parser.rb b/features/support/osm_parser.rb new file mode 100644 index 000000000..ea4e9bd16 --- /dev/null +++ b/features/support/osm_parser.rb @@ -0,0 +1,23 @@ +require 'OSM/StreamParser' + +class OSMTestParserCallbacks < OSM::Callbacks + @@locations = nil + + def self.locations + if @@locations + @@locations + else + #parse the test file, so we can later reference nodes and ways by name in tests + @@locations = {} + file = 'test/data/test.osm' + callbacks = OSMTestParserCallbacks.new + parser = OSM::StreamParser.new(:filename => file, :callbacks => callbacks) + parser.parse + puts @@locations + end + end + + def node(node) + @@locations[node.name] = [node.lat,node.lon] + end +end \ No newline at end of file diff --git a/features/support/request.rb b/features/support/request.rb deleted file mode 100644 index 8aeac53db..000000000 --- a/features/support/request.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'net/http' - -HOST = "http://localhost:#{OSRM_PORT}" -REQUEST_TIMEOUT = 1 - -def request_path path - @query = path - log path - uri = URI.parse "#{HOST}/#{path}" - Timeout.timeout(REQUEST_TIMEOUT) do - Net::HTTP.get_response uri - end -rescue Errno::ECONNREFUSED => e - raise "*** osrm-routed is not running." -rescue Timeout::Error - raise "*** osrm-routed did not respond." -end diff --git a/features/support/route.rb b/features/support/route.rb index d445f8f6f..856282a44 100644 --- a/features/support/route.rb +++ b/features/support/route.rb @@ -1,6 +1,23 @@ +require 'net/http' +HOST = "http://localhost:#{OSRM_PORT}" +REQUEST_TIMEOUT = 1 DESTINATION_REACHED = 15 #OSRM instruction code + +def request_path path + @query = path + log path + uri = URI.parse "#{HOST}/#{path}" + Timeout.timeout(REQUEST_TIMEOUT) do + Net::HTTP.get_response uri + end +rescue Errno::ECONNREFUSED => e + raise "*** osrm-routed is not running." +rescue Timeout::Error + raise "*** osrm-routed did not respond." +end + def request_route a,b request_path "viaroute?loc=#{a}&loc=#{b}&output=json&instructions=true&alt=true" end diff --git a/features/testbot/bad.feature b/features/testbot/bad.feature index 91ba269cc..aa3275a1f 100644 --- a/features/testbot/bad.feature +++ b/features/testbot/bad.feature @@ -2,7 +2,7 @@ Feature: Handle bad data in a graceful manner Background: - Given the speedprofile "testbot" + Given the profile "testbot" Scenario: Empty dataset Given the node map diff --git a/features/testbot/basic.feature b/features/testbot/basic.feature index 497c1f5d3..aabdcaa00 100644 --- a/features/testbot/basic.feature +++ b/features/testbot/basic.feature @@ -2,7 +2,7 @@ Feature: Basic Routing Background: - Given the speedprofile "testbot" + Given the profile "testbot" @smallest Scenario: A single way with two nodes diff --git a/features/testbot/bearing.feature b/features/testbot/bearing.feature index 69394390f..48ac5bd05 100644 --- a/features/testbot/bearing.feature +++ b/features/testbot/bearing.feature @@ -2,7 +2,7 @@ Feature: Compass bearing Background: - Given the speedprofile "testbot" + Given the profile "testbot" Scenario: Bearing when going northwest Given the node map diff --git a/features/testbot/distance.feature b/features/testbot/distance.feature index 167364512..ac1f38364 100644 --- a/features/testbot/distance.feature +++ b/features/testbot/distance.feature @@ -2,7 +2,7 @@ Feature: Distance calculation Background: - Given the speedprofile "testbot" + Given the profile "testbot" Scenario: 100m distance Given a grid size of 100 meters diff --git a/features/testbot/ferry.feature b/features/testbot/ferry.feature index f16518ef1..aadd083c0 100644 --- a/features/testbot/ferry.feature +++ b/features/testbot/ferry.feature @@ -2,7 +2,7 @@ Feature: Testbot - Handle ferry routes Background: - Given the speedprofile "testbot" + Given the profile "testbot" Scenario: Testbot - Ferry duration, single node Given the node map diff --git a/features/testbot/origin.feature b/features/testbot/origin.feature index 9f3979540..3fe6d97fc 100644 --- a/features/testbot/origin.feature +++ b/features/testbot/origin.feature @@ -2,7 +2,7 @@ Feature: Routing close to the [0,0] origin Background: - Given the speedprofile "testbot" + Given the profile "testbot" Scenario: East-west oneways close to the origin Given the node locations diff --git a/features/testbot/penalty.feature b/features/testbot/penalty.feature index f680eac4e..8b96050c9 100644 --- a/features/testbot/penalty.feature +++ b/features/testbot/penalty.feature @@ -3,7 +3,7 @@ Feature: Penalties Testbot uses a signal penalty of 7s. Background: - Given the speedprofile "testbot" + Given the profile "testbot" Scenario: Traffic signals should incur a delay, without changing distance Given the node map diff --git a/features/testbot/snap.feature b/features/testbot/snap.feature index c359cc4bf..ebed9f829 100644 --- a/features/testbot/snap.feature +++ b/features/testbot/snap.feature @@ -2,7 +2,7 @@ Feature: Snap start/end point to the nearest way Background: - Given the speedprofile "testbot" + Given the profile "testbot" Scenario: Snap to nearest protruding oneway Given the node map @@ -98,7 +98,6 @@ Feature: Snap start/end point to the nearest way | b | x | xb | | c | x | xc | - @xx Scenario: Find edges within 1km, but not 10km Given a grid size of 1000 meters Given the node map @@ -152,5 +151,4 @@ Feature: Snap start/end point to the nearest way | x | m | | | x | n | | | x | o | | - | x | p | | - + | x | p | | \ No newline at end of file diff --git a/features/testbot/time.feature b/features/testbot/time.feature index 0a19a3a37..b10544f8f 100644 --- a/features/testbot/time.feature +++ b/features/testbot/time.feature @@ -6,7 +6,7 @@ Secondary road: 18km/h = 18000m/3600s = 100m/20s Tertiary road: 12km/h = 12000m/3600s = 100m/30s Background: Use specific speeds - Given the speedprofile "testbot" + Given the profile "testbot" Scenario: Basic travel time, 10m scale Given a grid size of 10 meters diff --git a/features/testbot/turns.feature b/features/testbot/turns.feature index d87f2f7ce..4e50bc68e 100644 --- a/features/testbot/turns.feature +++ b/features/testbot/turns.feature @@ -2,7 +2,7 @@ Feature: Turn directions/codes Background: - Given the speedprofile "testbot" + Given the profile "testbot" Scenario: Turn directions Given the node map diff --git a/features/testbot/utf.feature b/features/testbot/utf.feature index 13d0c6fde..784bd4c80 100644 --- a/features/testbot/utf.feature +++ b/features/testbot/utf.feature @@ -2,7 +2,7 @@ Feature: Handling of UTF characters Background: - Given the speedprofile "testbot" + Given the profile "testbot" Scenario: Streetnames with UTF characters Given the node map diff --git a/features/testbot/weight.feature b/features/testbot/weight.feature index b884a37bf..0e3551ff2 100644 --- a/features/testbot/weight.feature +++ b/features/testbot/weight.feature @@ -2,7 +2,7 @@ Feature: Choosing route based on length, speed, etc Background: - Given the speedprofile "testbot" + Given the profile "testbot" Scenario: Pick the geometrically shortest route, way types being equal Given the node map