From 8b1f09d30288df281562f39974aec5b8242b80b3 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Thu, 27 Mar 2014 10:37:04 +0100 Subject: [PATCH] cuke: test speed, fix logging, clear log files on each run --- features/step_definitions/routability.rb | 27 +++++++++---------- features/step_definitions/routing.rb | 14 ++++++++-- features/support/data.rb | 2 -- features/support/env.rb | 4 +++ features/support/log.rb | 33 +++++++++++++++++++----- features/support/route.rb | 1 + features/testbot/speed.feature | 15 ++++++++++- 7 files changed, 71 insertions(+), 25 deletions(-) diff --git a/features/step_definitions/routability.rb b/features/step_definitions/routability.rb index 438924667..5c1d30d3d 100644 --- a/features/step_definitions/routability.rb +++ b/features/step_definitions/routability.rb @@ -5,6 +5,7 @@ def test_routability_row i b = Location.new @origin[0]+(3+WAY_SPACING*i)*@zoom, @origin[1] r = {} r[:response] = request_route direction=='forw' ? [a,b] : [b,a] + r[:query] = @query r[:json] = JSON.parse(r[:response].body) r[:status] = route_status r[:response] @@ -33,7 +34,7 @@ def test_routability_row i result['bothw'][key] = 'diff' end end - + result['bothw'][:response] = [result['forw'][:response],result['backw'][:response]] result end @@ -46,30 +47,30 @@ Then /^routability should be$/ do |table| end OSRMBackgroundLauncher.new("#{@osm_file}.osrm") do table.hashes.each_with_index do |row,i| - got = row.dup + output_row = row.dup attempts = [] result = test_routability_row i - (['forw','backw','bothw'] & table.headers).each do |direction| + directions = ['forw','backw','bothw'] + (directions & table.headers).each do |direction| want = shortcuts_hash[row[direction]] || row[direction] #expand shortcuts - case want when '', 'x' - got[direction] = result[direction][:status].to_s + output_row[direction] = result[direction][:status].to_s when /^\d+s/ - got[direction] = "#{result[direction][:time]}s" + output_row[direction] = "#{result[direction][:time]}s" when /^\d+ km\/h/ - got[direction] = "#{result[direction][:speed]} km/h" + output_row[direction] = "#{result[direction][:speed]} km/h" end - if FuzzyMatch.match got[direction], want - got[direction] = row[direction] - else -# attempts << { :attempt => direction, :query => @query, :response => result[direction][:response] } + if FuzzyMatch.match output_row[direction], want + output_row[direction] = row[direction] end end - log_fail row,got,attempts if got != row - actual << got + if output_row != row + log_fail row,output_row,result + end + actual << output_row end end table.routing_diff! actual diff --git a/features/step_definitions/routing.rb b/features/step_definitions/routing.rb index 8040719e7..24c6d6a7d 100644 --- a/features/step_definitions/routing.rb +++ b/features/step_definitions/routing.rb @@ -67,6 +67,17 @@ When /^I route I should get$/ do |table| raise "*** Time must be specied in seconds. (ex: 60s)" unless row['time'] =~ /\d+s/ got['time'] = instructions ? "#{json['route_summary']['total_time'].to_s}s" : '' end + if table.headers.include?('speed') + if row['speed'] != '' && instructions + raise "*** Speed must be specied in km/h. (ex: 50 km/h)" unless row['speed'] =~ /\d+ km\/h/ + time = json['route_summary']['total_time'] + distance = json['route_summary']['total_distance'] + speed = time>0 ? (3.6*distance/time).to_i : nil + got['speed'] = "#{speed} km/h" + else + got['speed'] = '' + end + end if table.headers.include? 'bearing' got['bearing'] = bearings end @@ -94,8 +105,7 @@ When /^I route I should get$/ do |table| end unless ok - failed = { :attempt => 'route', :query => @query, :response => response } - log_fail row,got,[failed] + log_fail row,got, { 'route' => {:query => @query, :response => response} } end actual << got diff --git a/features/support/data.rb b/features/support/data.rb index b11e460f7..c389e4e0a 100644 --- a/features/support/data.rb +++ b/features/support/data.rb @@ -7,8 +7,6 @@ OSM_GENERATOR = 'osrm-test' OSM_UID = 1 TEST_FOLDER = 'test' DATA_FOLDER = 'cache' -PREPROCESS_LOG_FILE = 'preprocessing.log' -LOG_FILE = 'fail.log' OSM_TIMESTAMP = '2000-00-00T00:00:00Z' DEFAULT_SPEEDPROFILE = 'bicycle' WAY_SPACING = 100 diff --git a/features/support/env.rb b/features/support/env.rb index a6a99b9f5..146838f38 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -16,3 +16,7 @@ else puts "Using default port #{OSRM_PORT}" end + +AfterConfiguration do |config| + clear_log_files +end \ No newline at end of file diff --git a/features/support/log.rb b/features/support/log.rb index 1607bfb59..e5d34cc26 100644 --- a/features/support/log.rb +++ b/features/support/log.rb @@ -1,3 +1,19 @@ +# logging + +PREPROCESS_LOG_FILE = 'preprocessing.log' +LOG_FILE = 'fail.log' + + +def clear_log_files + Dir.chdir TEST_FOLDER do + # emptying existing files, rather than deleting and writing new ones makes it + # easier to use tail -f from the command line + `echo '' > #{OSRM_ROUTED_LOG_FILE}` + `echo '' > #{PREPROCESS_LOG_FILE}` + `echo '' > #{LOG_FILE}` + end +end + def log s='', type=nil if type == :preprocess file = PREPROCESS_LOG_FILE @@ -24,17 +40,20 @@ def log_scenario_fail_info @has_logged_scenario_info = true end -def log_fail expected,actual,failed +def log_fail expected,got,attempts log_scenario_fail_info log "== " log "Expected: #{expected}" - log "Got: #{actual}" + log "Got: #{got}" log - failed.each do |fail| - log "Attempt: #{fail[:attempt]}" - log "Query: #{fail[:query]}" - log "Response: #{fail[:response].body}" - log + ['route','forw','backw'].each do |direction| + if attempts[direction] + attempts[direction] + log "Direction: #{direction}" + log "Query: #{attempts[direction][:query]}" + log "Response: #{attempts[direction][:response].body}" + log + end end end diff --git a/features/support/route.rb b/features/support/route.rb index b1cb71b01..417ba0d49 100644 --- a/features/support/route.rb +++ b/features/support/route.rb @@ -17,6 +17,7 @@ def request_path path, waypoints=[], options={} params = (locs + options.to_param).join('&') params = nil if params=="" uri = URI.parse ["#{HOST}/#{path}", params].compact.join('?') + @query = uri.to_s Timeout.timeout(REQUEST_TIMEOUT) do Net::HTTP.get_response uri end diff --git a/features/testbot/speed.feature b/features/testbot/speed.feature index 1f183750c..c9a983136 100644 --- a/features/testbot/speed.feature +++ b/features/testbot/speed.feature @@ -12,7 +12,20 @@ Feature: Testbot - speeds | secondary | 18 km/h | | tertiary | 12 km/h | - Scenario: Testbot - Speed on rivers + Scenario: Testbot - Speed on rivers, table Then routability should be | highway | forw | backw | | river | 36 km/h | 16 km/h | + + Scenario: Testbot - Speed on rivers, map + Given the node map + | a | b | + + And the ways + | nodes | highway | + | ab | river | + + When I route I should get + | from | to | route | speed | time | distance | + | a | b | ab | 36 km/h | 10s | 100m | + | b | a | ab | 16 km/h | 22s | 100m |