From 102e87bcc0291d2334407d356121639128fcaa03 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Mon, 17 Dec 2012 19:27:18 +0100 Subject: [PATCH] clean up log extracts during cuke failures --- features/step_definitions/requests.rb | 2 +- features/support/data.rb | 21 ++----------- features/support/exceptions.rb | 45 ++++++++++++++++++++++++--- features/support/launch.rb | 13 +++----- 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/features/step_definitions/requests.rb b/features/step_definitions/requests.rb index 6de50c324..d965b1aa0 100644 --- a/features/step_definitions/requests.rb +++ b/features/step_definitions/requests.rb @@ -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 diff --git a/features/support/data.rb b/features/support/data.rb index 8dd6aab69..392265da4 100644 --- a/features/support/data.rb +++ b/features/support/data.rb @@ -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 diff --git a/features/support/exceptions.rb b/features/support/exceptions.rb index 730411379..22a6868ab 100644 --- a/features/support/exceptions.rb +++ b/features/support/exceptions.rb @@ -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 \ No newline at end of file + + 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 diff --git a/features/support/launch.rb b/features/support/launch.rb index 0b07b87e4..8df2f27f5 100644 --- a/features/support/launch.rb +++ b/features/support/launch.rb @@ -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