cuke: test speed, fix logging, clear log files on each run
This commit is contained in:
parent
cb1b824a75
commit
8b1f09d302
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -16,3 +16,7 @@ else
|
||||
puts "Using default port #{OSRM_PORT}"
|
||||
end
|
||||
|
||||
|
||||
AfterConfiguration do |config|
|
||||
clear_log_files
|
||||
end
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 |
|
||||
|
Loading…
Reference in New Issue
Block a user