1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Only allow process that started server to shut it down.

This commit is contained in:
Matthew Mongeau 2011-10-14 15:49:07 -04:00
parent b4708b2b88
commit 3eb366e011
2 changed files with 20 additions and 5 deletions

View file

@ -111,14 +111,20 @@ class Capybara::Driver::Webkit
def fork_server
server_path = File.expand_path("../../../../../bin/webkit_server", __FILE__)
pipe, @pid = server_pipe_and_pid(server_path)
at_exit { Process.kill("INT", @pid) }
register_shutdown_hook
pipe
end
def register_shutdown_hook
@owner_pid = Process.pid
at_exit do
if Process.pid == @owner_pid
Process.kill("INT", @pid)
end
end
end
def server_pipe_and_pid(server_path)
pipe = IO.popen(server_path)
[pipe, pipe.pid]

View file

@ -32,4 +32,13 @@ describe Capybara::Driver::Webkit::Browser do
io.string.should == "hello world\n"
end
describe "forking" do
it "only shuts down the server from the main process" do
browser.reset!
pid = fork {}
Process.wait(pid)
expect { browser.reset! }.not_to raise_error
end
end
end