Explicitly shutdown webkit_server when shutting down - Issue #944
This commit is contained in:
parent
dc1a151664
commit
e9909f655c
|
@ -29,7 +29,7 @@ matrix:
|
|||
env: QMAKE=/usr/lib/x86_64-linux-gnu/qt4/bin/qmake
|
||||
- rvm: 2.3.3
|
||||
gemfile: gemfiles/master.gemfile
|
||||
- rvm: jruby-9.1.8.0
|
||||
- rvm: jruby-9.1.13.0
|
||||
gemfile: Gemfile
|
||||
allow_failures:
|
||||
- gemfile: gemfiles/master.gemfile
|
||||
|
|
|
@ -26,15 +26,23 @@ module Capybara
|
|||
discover_port
|
||||
discover_pid
|
||||
forward_output_in_background_thread
|
||||
register_shutdown_hook
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def open_pipe
|
||||
@pipe_stdin,
|
||||
@pipe_stdout,
|
||||
@pipe_stderr,
|
||||
@wait_thr = Open3.popen3(SERVER_PATH)
|
||||
if IO.respond_to?(:popen4)
|
||||
@pid,
|
||||
@pipe_stdin,
|
||||
@pipe_stdout,
|
||||
@pipe_stderr = IO.popen4(SERVER_PATH)
|
||||
else
|
||||
@pipe_stdin,
|
||||
@pipe_stdout,
|
||||
@pipe_stderr,
|
||||
@wait_thr = Open3.popen3(SERVER_PATH)
|
||||
end
|
||||
end
|
||||
|
||||
def discover_port
|
||||
|
@ -58,7 +66,7 @@ module Capybara
|
|||
end
|
||||
|
||||
def discover_pid
|
||||
@pid = @wait_thr[:pid]
|
||||
@pid ||= @wait_thr[:pid]
|
||||
end
|
||||
|
||||
def forward_output_in_background_thread
|
||||
|
@ -67,6 +75,31 @@ module Capybara
|
|||
IO.copy_stream(@pipe_stderr, @output_target) if @output_target
|
||||
end
|
||||
end
|
||||
|
||||
def register_shutdown_hook
|
||||
@owner_pid = Process.pid
|
||||
at_exit do
|
||||
if Process.pid == @owner_pid
|
||||
kill_process
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def kill_process
|
||||
if @pid
|
||||
if RUBY_PLATFORM =~ /mingw32/
|
||||
Process.kill(9, @pid)
|
||||
else
|
||||
Process.kill("INT", @pid)
|
||||
end
|
||||
Process.wait(@pid)
|
||||
@wait_thr.join if @wait_thr
|
||||
end
|
||||
rescue Errno::ESRCH, Errno::ECHILD
|
||||
# This just means that the webkit_server process has already ended
|
||||
ensure
|
||||
@pid = @wait_thr = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue