kill osrm-routed if it refuses to shutdown in cuke tests
This commit is contained in:
parent
7f7055a9e7
commit
7e9614b9ec
@ -1,14 +1,24 @@
|
||||
require 'socket'
|
||||
require 'sys/proctable'
|
||||
|
||||
LAUNCH_TIMEOUT = 5
|
||||
SHUTDOWN_TIMEOUT = 5
|
||||
LAUNCH_TIMEOUT = 2
|
||||
SHUTDOWN_TIMEOUT = 2
|
||||
|
||||
class OSRMLauncher
|
||||
def initialize &block
|
||||
Dir.chdir TEST_FOLDER do
|
||||
begin
|
||||
begin
|
||||
launch
|
||||
yield
|
||||
ensure
|
||||
shutdown
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def launch
|
||||
Timeout.timeout(LAUNCH_TIMEOUT) do
|
||||
osrm_up
|
||||
wait_for_connection
|
||||
@ -16,21 +26,18 @@ class OSRMLauncher
|
||||
rescue Timeout::Error
|
||||
raise "*** Launching osrm-routed timed out."
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
begin
|
||||
|
||||
def shutdown
|
||||
Timeout.timeout(SHUTDOWN_TIMEOUT) do
|
||||
osrm_down
|
||||
end
|
||||
rescue Timeout::Error
|
||||
kill
|
||||
raise "*** Shutting down osrm-routed timed out."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def osrm_up?
|
||||
|
||||
def osrm_up?
|
||||
if @pipe
|
||||
begin
|
||||
Process.getpgid @pipe.pid
|
||||
@ -41,31 +48,30 @@ def osrm_up?
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def osrm_up
|
||||
def osrm_up
|
||||
return if osrm_up?
|
||||
#exec avoids popen running osrm-routed inside a shell
|
||||
#if the cmd is run inside a shell, popen returns the pid for the shell, and if we try to kill it,
|
||||
#the child process is orphaned, and we can't terminate it.
|
||||
@pipe = IO.popen('exec ../osrm-routed 1>>osrm-routed.log 2>>osrm-routed.log')
|
||||
end
|
||||
end
|
||||
|
||||
def osrm_down
|
||||
def osrm_down
|
||||
if @pipe
|
||||
Process.kill 'TERM', @pipe.pid
|
||||
wait_for_shutdown
|
||||
@pipe = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def kill
|
||||
def kill
|
||||
if @pipe
|
||||
Process.kill 'KILL', @pipe.pid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def wait_for_connection
|
||||
def wait_for_connection
|
||||
while true
|
||||
begin
|
||||
socket = TCPSocket.new('localhost', OSRM_PORT)
|
||||
@ -74,10 +80,11 @@ def wait_for_connection
|
||||
sleep 0.1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def wait_for_shutdown
|
||||
def wait_for_shutdown
|
||||
while osrm_up?
|
||||
sleep 0.1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user