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]
|
b = Location.new @origin[0]+(3+WAY_SPACING*i)*@zoom, @origin[1]
|
||||||
r = {}
|
r = {}
|
||||||
r[:response] = request_route direction=='forw' ? [a,b] : [b,a]
|
r[:response] = request_route direction=='forw' ? [a,b] : [b,a]
|
||||||
|
r[:query] = @query
|
||||||
r[:json] = JSON.parse(r[:response].body)
|
r[:json] = JSON.parse(r[:response].body)
|
||||||
|
|
||||||
r[:status] = route_status r[:response]
|
r[:status] = route_status r[:response]
|
||||||
@ -33,7 +34,7 @@ def test_routability_row i
|
|||||||
result['bothw'][key] = 'diff'
|
result['bothw'][key] = 'diff'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
result['bothw'][:response] = [result['forw'][:response],result['backw'][:response]]
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -46,30 +47,30 @@ Then /^routability should be$/ do |table|
|
|||||||
end
|
end
|
||||||
OSRMBackgroundLauncher.new("#{@osm_file}.osrm") do
|
OSRMBackgroundLauncher.new("#{@osm_file}.osrm") do
|
||||||
table.hashes.each_with_index do |row,i|
|
table.hashes.each_with_index do |row,i|
|
||||||
got = row.dup
|
output_row = row.dup
|
||||||
attempts = []
|
attempts = []
|
||||||
result = test_routability_row i
|
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
|
want = shortcuts_hash[row[direction]] || row[direction] #expand shortcuts
|
||||||
|
|
||||||
case want
|
case want
|
||||||
when '', 'x'
|
when '', 'x'
|
||||||
got[direction] = result[direction][:status].to_s
|
output_row[direction] = result[direction][:status].to_s
|
||||||
when /^\d+s/
|
when /^\d+s/
|
||||||
got[direction] = "#{result[direction][:time]}s"
|
output_row[direction] = "#{result[direction][:time]}s"
|
||||||
when /^\d+ km\/h/
|
when /^\d+ km\/h/
|
||||||
got[direction] = "#{result[direction][:speed]} km/h"
|
output_row[direction] = "#{result[direction][:speed]} km/h"
|
||||||
end
|
end
|
||||||
|
|
||||||
if FuzzyMatch.match got[direction], want
|
if FuzzyMatch.match output_row[direction], want
|
||||||
got[direction] = row[direction]
|
output_row[direction] = row[direction]
|
||||||
else
|
|
||||||
# attempts << { :attempt => direction, :query => @query, :response => result[direction][:response] }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
log_fail row,got,attempts if got != row
|
if output_row != row
|
||||||
actual << got
|
log_fail row,output_row,result
|
||||||
|
end
|
||||||
|
actual << output_row
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.routing_diff! actual
|
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/
|
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" : ''
|
got['time'] = instructions ? "#{json['route_summary']['total_time'].to_s}s" : ''
|
||||||
end
|
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'
|
if table.headers.include? 'bearing'
|
||||||
got['bearing'] = bearings
|
got['bearing'] = bearings
|
||||||
end
|
end
|
||||||
@ -94,8 +105,7 @@ When /^I route I should get$/ do |table|
|
|||||||
end
|
end
|
||||||
|
|
||||||
unless ok
|
unless ok
|
||||||
failed = { :attempt => 'route', :query => @query, :response => response }
|
log_fail row,got, { 'route' => {:query => @query, :response => response} }
|
||||||
log_fail row,got,[failed]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
actual << got
|
actual << got
|
||||||
|
@ -7,8 +7,6 @@ OSM_GENERATOR = 'osrm-test'
|
|||||||
OSM_UID = 1
|
OSM_UID = 1
|
||||||
TEST_FOLDER = 'test'
|
TEST_FOLDER = 'test'
|
||||||
DATA_FOLDER = 'cache'
|
DATA_FOLDER = 'cache'
|
||||||
PREPROCESS_LOG_FILE = 'preprocessing.log'
|
|
||||||
LOG_FILE = 'fail.log'
|
|
||||||
OSM_TIMESTAMP = '2000-00-00T00:00:00Z'
|
OSM_TIMESTAMP = '2000-00-00T00:00:00Z'
|
||||||
DEFAULT_SPEEDPROFILE = 'bicycle'
|
DEFAULT_SPEEDPROFILE = 'bicycle'
|
||||||
WAY_SPACING = 100
|
WAY_SPACING = 100
|
||||||
|
@ -16,3 +16,7 @@ else
|
|||||||
puts "Using default port #{OSRM_PORT}"
|
puts "Using default port #{OSRM_PORT}"
|
||||||
end
|
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
|
def log s='', type=nil
|
||||||
if type == :preprocess
|
if type == :preprocess
|
||||||
file = PREPROCESS_LOG_FILE
|
file = PREPROCESS_LOG_FILE
|
||||||
@ -24,17 +40,20 @@ def log_scenario_fail_info
|
|||||||
@has_logged_scenario_info = true
|
@has_logged_scenario_info = true
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_fail expected,actual,failed
|
def log_fail expected,got,attempts
|
||||||
log_scenario_fail_info
|
log_scenario_fail_info
|
||||||
log "== "
|
log "== "
|
||||||
log "Expected: #{expected}"
|
log "Expected: #{expected}"
|
||||||
log "Got: #{actual}"
|
log "Got: #{got}"
|
||||||
log
|
log
|
||||||
failed.each do |fail|
|
['route','forw','backw'].each do |direction|
|
||||||
log "Attempt: #{fail[:attempt]}"
|
if attempts[direction]
|
||||||
log "Query: #{fail[:query]}"
|
attempts[direction]
|
||||||
log "Response: #{fail[:response].body}"
|
log "Direction: #{direction}"
|
||||||
log
|
log "Query: #{attempts[direction][:query]}"
|
||||||
|
log "Response: #{attempts[direction][:response].body}"
|
||||||
|
log
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ def request_path path, waypoints=[], options={}
|
|||||||
params = (locs + options.to_param).join('&')
|
params = (locs + options.to_param).join('&')
|
||||||
params = nil if params==""
|
params = nil if params==""
|
||||||
uri = URI.parse ["#{HOST}/#{path}", params].compact.join('?')
|
uri = URI.parse ["#{HOST}/#{path}", params].compact.join('?')
|
||||||
|
@query = uri.to_s
|
||||||
Timeout.timeout(REQUEST_TIMEOUT) do
|
Timeout.timeout(REQUEST_TIMEOUT) do
|
||||||
Net::HTTP.get_response uri
|
Net::HTTP.get_response uri
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,20 @@ Feature: Testbot - speeds
|
|||||||
| secondary | 18 km/h |
|
| secondary | 18 km/h |
|
||||||
| tertiary | 12 km/h |
|
| tertiary | 12 km/h |
|
||||||
|
|
||||||
Scenario: Testbot - Speed on rivers
|
Scenario: Testbot - Speed on rivers, table
|
||||||
Then routability should be
|
Then routability should be
|
||||||
| highway | forw | backw |
|
| highway | forw | backw |
|
||||||
| river | 36 km/h | 16 km/h |
|
| 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