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
|
env: QMAKE=/usr/lib/x86_64-linux-gnu/qt4/bin/qmake
|
||||||
- rvm: 2.3.3
|
- rvm: 2.3.3
|
||||||
gemfile: gemfiles/master.gemfile
|
gemfile: gemfiles/master.gemfile
|
||||||
- rvm: jruby-9.1.8.0
|
- rvm: jruby-9.1.13.0
|
||||||
gemfile: Gemfile
|
gemfile: Gemfile
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- gemfile: gemfiles/master.gemfile
|
- gemfile: gemfiles/master.gemfile
|
||||||
|
|
|
@ -26,15 +26,23 @@ module Capybara
|
||||||
discover_port
|
discover_port
|
||||||
discover_pid
|
discover_pid
|
||||||
forward_output_in_background_thread
|
forward_output_in_background_thread
|
||||||
|
register_shutdown_hook
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def open_pipe
|
def open_pipe
|
||||||
@pipe_stdin,
|
if IO.respond_to?(:popen4)
|
||||||
@pipe_stdout,
|
@pid,
|
||||||
@pipe_stderr,
|
@pipe_stdin,
|
||||||
@wait_thr = Open3.popen3(SERVER_PATH)
|
@pipe_stdout,
|
||||||
|
@pipe_stderr = IO.popen4(SERVER_PATH)
|
||||||
|
else
|
||||||
|
@pipe_stdin,
|
||||||
|
@pipe_stdout,
|
||||||
|
@pipe_stderr,
|
||||||
|
@wait_thr = Open3.popen3(SERVER_PATH)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def discover_port
|
def discover_port
|
||||||
|
@ -58,7 +66,7 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def discover_pid
|
def discover_pid
|
||||||
@pid = @wait_thr[:pid]
|
@pid ||= @wait_thr[:pid]
|
||||||
end
|
end
|
||||||
|
|
||||||
def forward_output_in_background_thread
|
def forward_output_in_background_thread
|
||||||
|
@ -67,6 +75,31 @@ module Capybara
|
||||||
IO.copy_stream(@pipe_stderr, @output_target) if @output_target
|
IO.copy_stream(@pipe_stderr, @output_target) if @output_target
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue