cuke: optional timeout

This commit is contained in:
Emil Tin 2014-03-31 16:05:09 +02:00
parent 179f53b21b
commit ba2356d2ba
5 changed files with 14 additions and 9 deletions

View File

@ -1,7 +1,7 @@
require 'rspec/expectations' require 'rspec/expectations'
DEFAULT_PORT = 5000 DEFAULT_PORT = 5000
DEFAULT_TIMEOUT = 2
puts "Ruby version #{RUBY_VERSION}" puts "Ruby version #{RUBY_VERSION}"
unless RUBY_VERSION.to_f >= 1.9 unless RUBY_VERSION.to_f >= 1.9
@ -16,6 +16,14 @@ else
puts "Using default port #{OSRM_PORT}" puts "Using default port #{OSRM_PORT}"
end end
if ENV["OSRM_TIMEOUT"]
OSRM_TIMEOUT = ENV["OSRM_TIMEOUT"].to_i
puts "Timeout set to #{OSRM_TIMEOUT}"
else
OSRM_TIMEOUT = DEFAULT_TIMEOUT
puts "Using default timeout #{OSRM_TIMEOUT}"
end
AfterConfiguration do |config| AfterConfiguration do |config|
clear_log_files clear_log_files

View File

@ -1,8 +1,6 @@
require 'socket' require 'socket'
require 'open3' require 'open3'
LAUNCH_TIMEOUT = 20
SHUTDOWN_TIMEOUT = 20
OSRM_ROUTED_LOG_FILE = 'osrm-routed.log' OSRM_ROUTED_LOG_FILE = 'osrm-routed.log'
class OSRMBackgroundLauncher class OSRMBackgroundLauncher
@ -21,7 +19,7 @@ class OSRMBackgroundLauncher
private private
def launch def launch
Timeout.timeout(LAUNCH_TIMEOUT) do Timeout.timeout(OSRM_TIMEOUT) do
osrm_up osrm_up
wait_for_connection wait_for_connection
end end
@ -30,7 +28,7 @@ class OSRMBackgroundLauncher
end end
def shutdown def shutdown
Timeout.timeout(SHUTDOWN_TIMEOUT) do Timeout.timeout(OSRM_TIMEOUT) do
osrm_down osrm_down
end end
rescue Timeout::Error rescue Timeout::Error

View File

@ -3,7 +3,7 @@ require 'net/http'
def request_locate_url path def request_locate_url path
@query = path @query = path
uri = URI.parse "#{HOST}/#{path}" uri = URI.parse "#{HOST}/#{path}"
Timeout.timeout(REQUEST_TIMEOUT) do Timeout.timeout(OSRM_TIMEOUT) do
Net::HTTP.get_response uri Net::HTTP.get_response uri
end end
rescue Errno::ECONNREFUSED => e rescue Errno::ECONNREFUSED => e

View File

@ -3,7 +3,7 @@ require 'net/http'
def request_nearest_url path def request_nearest_url path
@query = path @query = path
uri = URI.parse "#{HOST}/#{path}" uri = URI.parse "#{HOST}/#{path}"
Timeout.timeout(REQUEST_TIMEOUT) do Timeout.timeout(OSRM_TIMEOUT) do
Net::HTTP.get_response uri Net::HTTP.get_response uri
end end
rescue Errno::ECONNREFUSED => e rescue Errno::ECONNREFUSED => e

View File

@ -1,7 +1,6 @@
require 'net/http' require 'net/http'
HOST = "http://localhost:#{OSRM_PORT}" HOST = "http://localhost:#{OSRM_PORT}"
REQUEST_TIMEOUT = 1
DESTINATION_REACHED = 15 #OSRM instruction code DESTINATION_REACHED = 15 #OSRM instruction code
class Hash class Hash
@ -18,7 +17,7 @@ def request_path path, waypoints=[], options={}
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 @query = uri.to_s
Timeout.timeout(REQUEST_TIMEOUT) do Timeout.timeout(OSRM_TIMEOUT) do
Net::HTTP.get_response uri Net::HTTP.get_response uri
end end
rescue Errno::ECONNREFUSED => e rescue Errno::ECONNREFUSED => e