clean up log extracts during cuke failures

This commit is contained in:
Emil Tin 2012-12-17 19:27:18 +01:00
parent 604043e3d8
commit 102e87bcc0
4 changed files with 48 additions and 33 deletions

View File

@ -39,7 +39,7 @@ When /^I preprocess data$/ do
end
Then /^"([^"]*)" should return code (\d+)$/ do |binary, code|
@process_error.class.should == OSRMError
@process_error.is_a?(OSRMError).should == true
@process_error.process.should == binary
@process_error.code.to_i.should == code.to_i
end

View File

@ -177,10 +177,7 @@ def convert_osm_to_pbf
log_preprocess_info
log "== Converting #{@osm_file}.osm to protobuffer format...", :preprocess
unless system "osmosis --read-xml #{@osm_file}.osm --write-pbf #{@osm_file}.osm.pbf omitmetadata=true 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE}"
log_path = 'preprocessing.log'
log_lines = 30
tail = log_tail log_path,log_lines
raise OSRMError.new 'osmosis', $?.exitstatus, "*** Failed to convert .oms to .pbf. osmosis exited with code #{$?.exitstatus}. Last #{log_lines} lines from #{log_path}:\n#{tail}\n"
raise OsmosisError.new $?, "osmosis exited with code #{$?.exitstatus}"
end
log '', :preprocess
end
@ -200,28 +197,17 @@ def write_timestamp
File.open( "#{@osm_file}.osrm.timestamp", 'w') {|f| f.write(OSM_TIMESTAMP) }
end
def log_tail path, n
File.open(path) do |f|
return f.tail(n).map { |line| " #{line}" }.join "\n"
end
end
def reprocess
Dir.chdir TEST_FOLDER do
write_osm
write_timestamp
convert_osm_to_pbf
log_path = 'preprocessing.log'
log_lines = 3
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/#{@profile}.lua"
log "*** Exited with code #{$?.exitstatus}.", :preprocess
tail = log_tail log_path,log_lines
raise OSRMError.new 'osrm-extract', $?.exitstatus, "*** osrm-extract exited with code #{$?.exitstatus}. Last #{log_lines} lines from #{log_path}:\n#{tail}\n"
raise ExtractError.new $?.exitstatus, "osrm-extract exited with code #{$?.exitstatus}."
end
log '', :preprocess
end
@ -230,8 +216,7 @@ def reprocess
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/#{@profile}.lua"
log "*** Exited with code #{$?.exitstatus}.", :preprocess
tail = log_tail log_path,log_lines
raise OSRMError.new 'osrm-prepare', $?.exitstatus, "*** osrm-prepare exited with code #{$?.exitstatus}. Last #{log_lines} lines from #{log_path}:\n#{tail}\n"
raise PrepareError.new $?.exitstatus, "osrm-prepare exited with code #{$?.exitstatus}."
end
log '', :preprocess
end

View File

@ -1,14 +1,49 @@
class OSRMError < StandardError
attr_accessor :process, :code, :msg
def initialize process, code, msg
attr_accessor :msg, :code, :process
def initialize process, code, msg, log, lines
@process = process
@code = code
@msg = msg
@lines = lines
@log = log
@extract = log_tail @log, @lines
end
def to_s
@msg
"*** #{@msg}\nLast #{@lines} lines from #{@log}:\n#{@extract}\n"
end
end
private
def log_tail path, n
File.open(path) do |f|
return f.tail(n).map { |line| " > #{line}" }.join "\n"
end
end
end
class OsmosisError < OSRMError
def initialize code, msg
super 'osmosis', code, msg, PREPROCESS_LOG_FILE, 40
end
end
class ExtractError < OSRMError
def initialize code, msg
super 'osrm-extract', code, msg, PREPROCESS_LOG_FILE, 3
end
end
class PrepareError < OSRMError
def initialize code, msg
super 'osrm-prepare', code, msg, PREPROCESS_LOG_FILE, 3
end
end
class RoutedError < OSRMError
def initialize msg
super 'osrm-routed', nil, msg, OSRM_ROUTED_LOG_FILE, 3
end
end

View File

@ -3,6 +3,7 @@ require 'open3'
LAUNCH_TIMEOUT = 2
SHUTDOWN_TIMEOUT = 2
OSRM_ROUTED_LOG_FILE = 'osrm-routed.log'
class OSRMLauncher
def initialize &block
@ -24,10 +25,7 @@ class OSRMLauncher
wait_for_connection
end
rescue Timeout::Error
log_path = 'osrm-routed.log'
log_lines = 3
tail = log_tail log_path,log_lines
raise OSRMError.new 'osrm-routed', nil, "*** Launching osrm-routed timed out. Last #{log_lines} lines from #{log_path}:\n#{tail}\n"
raise RoutedError.new "Launching osrm-routed timed out."
end
def shutdown
@ -36,10 +34,7 @@ class OSRMLauncher
end
rescue Timeout::Error
kill
log_path = 'osrm-routed.log'
log_lines = 3
tail = log_tail log_path,log_lines
raise OSRMError.new 'osrm-routed', nil, "*** Shutting down osrm-routed timed out. Last #{log_lines} lines from #{log_path}:\n#{tail}\n"
raise RoutedError.new "Shutting down osrm-routed timed out."
end
@ -53,7 +48,7 @@ class OSRMLauncher
def osrm_up
return if osrm_up?
@pid = Process.spawn(['../osrm-routed',''],:out=>'osrm-routed.log', :err=>'osrm-routed.log')
@pid = Process.spawn(['../osrm-routed',''],:out=>OSRM_ROUTED_LOG_FILE, :err=>OSRM_ROUTED_LOG_FILE)
end
def osrm_down