From d0284991ed9d29581b2ec58d54735a51d4927a77 Mon Sep 17 00:00:00 2001 From: alex85k Date: Wed, 30 Apr 2014 14:30:51 +0600 Subject: [PATCH] patch Ruby files for successful testing on Windows --- features/support/data.rb | 6 +++--- features/support/env.rb | 7 +++++++ features/support/hash.rb | 8 ++++---- features/support/launch.rb | 22 +++++++++++++++++----- features/support/route.rb | 2 +- features/support/run.rb | 4 ++-- 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/features/support/data.rb b/features/support/data.rb index 58d5de759..7c1ba887a 100644 --- a/features/support/data.rb +++ b/features/support/data.rb @@ -217,7 +217,7 @@ def convert_osm_to_pbf unless File.exist?("#{@osm_file}.osm.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}" + unless system "osmosis --read-xml #{@osm_file}.osm --write-pbf #{@osm_file}.osm.pbf omitmetadata=true >>#{PREPROCESS_LOG_FILE} 2>&1" raise OsmosisError.new $?, "osmosis exited with code #{$?.exitstatus}" end log '', :preprocess @@ -253,7 +253,7 @@ def extract_data Dir.chdir TEST_FOLDER do log_preprocess_info log "== Extracting #{@osm_file}.osm...", :preprocess - unless system "#{BIN_PATH}/osrm-extract #{@osm_file}.osm#{'.pbf' if pbf?} --profile #{PROFILES_PATH}/#{@profile}.lua 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE}" + unless system "#{BIN_PATH}/osrm-extract #{@osm_file}.osm#{'.pbf' if pbf?} --profile #{PROFILES_PATH}/#{@profile}.lua >>#{PREPROCESS_LOG_FILE} 2>&1" log "*** Exited with code #{$?.exitstatus}.", :preprocess raise ExtractError.new $?.exitstatus, "osrm-extract exited with code #{$?.exitstatus}." end @@ -265,7 +265,7 @@ def prepare_data Dir.chdir TEST_FOLDER do log_preprocess_info log "== Preparing #{@osm_file}.osm...", :preprocess - unless system "#{BIN_PATH}/osrm-prepare #{@osm_file}.osrm --profile #{PROFILES_PATH}/#{@profile}.lua 1>>#{PREPROCESS_LOG_FILE} 2>>#{PREPROCESS_LOG_FILE}" + unless system "#{BIN_PATH}/osrm-prepare #{@osm_file}.osrm --profile #{PROFILES_PATH}/#{@profile}.lua >>#{PREPROCESS_LOG_FILE} 2>&1" log "*** Exited with code #{$?.exitstatus}.", :preprocess raise PrepareError.new $?.exitstatus, "osrm-prepare exited with code #{$?.exitstatus}." end diff --git a/features/support/env.rb b/features/support/env.rb index b1eeb64b6..a6a9ca00e 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -44,6 +44,13 @@ unless File.exists? TEST_FOLDER raise "*** Test folder #{TEST_FOLDER} doesn't exist." end +if ENV['OS']=~/Windows.*/ then + EXE='.exe' + QQ='"' +else + EXE='' + QQ='' +end AfterConfiguration do |config| clear_log_files diff --git a/features/support/hash.rb b/features/support/hash.rb index 6381af62d..197cd426e 100644 --- a/features/support/hash.rb +++ b/features/support/hash.rb @@ -7,7 +7,7 @@ def hash_of_files paths paths = [paths] unless paths.is_a? Array hash = Digest::SHA1.new for path in paths do - open(path,'r') do |io| + open(path,'rb') do |io| while !io.eof buf = io.readpartial 1024 hash.update buf @@ -32,15 +32,15 @@ def lua_lib_hash end def bin_extract_hash - bin_extract_hash ||= hash_of_files "#{BIN_PATH}/osrm-extract" + bin_extract_hash ||= hash_of_files "#{BIN_PATH}/osrm-extract#{EXE}" end def bin_prepare_hash - bin_prepare_hash ||= hash_of_files "#{BIN_PATH}/osrm-prepare" + bin_prepare_hash ||= hash_of_files "#{BIN_PATH}/osrm-prepare#{EXE}" end def bin_routed_hash - bin_routed_hash ||= hash_of_files "#{BIN_PATH}/osrm-routed" + bin_routed_hash ||= hash_of_files "#{BIN_PATH}/osrm-routed#{EXE}" end #combine state of data, profile and binaries into a hash that identifies the exact test scenario diff --git a/features/support/launch.rb b/features/support/launch.rb index 6699fb947..e55867a67 100644 --- a/features/support/launch.rb +++ b/features/support/launch.rb @@ -1,6 +1,12 @@ require 'socket' require 'open3' +if ENV['OS']==/Windows.*/ then + TERMSIGNAL='TERM' +else + TERMSIGNAL=9 +end + OSRM_ROUTED_LOG_FILE = 'osrm-routed.log' class OSRMBackgroundLauncher @@ -39,9 +45,15 @@ class OSRMBackgroundLauncher def osrm_up? if @pid - `ps -o state -p #{@pid}`.split[1].to_s =~ /^[DRST]/ - else - false + begin + if Process.waitpid(@pid, Process::WNOHANG) then + false + else + true + end + rescue Errno::ESRCH, Errno::ECHILD + false + end end end @@ -53,7 +65,7 @@ class OSRMBackgroundLauncher def osrm_down if @pid - Process.kill 'TERM', @pid + Process.kill TERMSIGNAL, @pid wait_for_shutdown end end @@ -67,7 +79,7 @@ class OSRMBackgroundLauncher def wait_for_connection while true begin - socket = TCPSocket.new('localhost', OSRM_PORT) + socket = TCPSocket.new('127.0.0.1', OSRM_PORT) return rescue Errno::ECONNREFUSED sleep 0.1 diff --git a/features/support/route.rb b/features/support/route.rb index 2f930751e..a88216b7e 100644 --- a/features/support/route.rb +++ b/features/support/route.rb @@ -1,6 +1,6 @@ require 'net/http' -HOST = "http://localhost:#{OSRM_PORT}" +HOST = "http://127.0.0.1:#{OSRM_PORT}" DESTINATION_REACHED = 15 #OSRM instruction code class Hash diff --git a/features/support/run.rb b/features/support/run.rb index 236c873d9..794050a32 100644 --- a/features/support/run.rb +++ b/features/support/run.rb @@ -10,8 +10,8 @@ def run_bin bin, options if opt.include? '{profile}' opt.gsub! "{profile}", "#{PROFILES_PATH}/#{@profile}.lua" end - - @stdout = `#{BIN_PATH}/#{bin} #{opt} 2>error.log` + + @stdout = `#{QQ}#{BIN_PATH}/#{bin}#{EXE}#{QQ} #{opt} 2>error.log` @stderr = File.read 'error.log' @exit_code = $?.exitstatus end