Permalink
Browse files

Only allow process that started server to shut it down.

  • Loading branch information...
1 parent b4708b2 commit 3eb366e011b821ae2843a48cd52739be359f88d0 @halogenandtoast halogenandtoast committed Oct 14, 2011
Showing with 20 additions and 5 deletions.
  1. +10 −4 lib/capybara/driver/webkit/browser.rb
  2. +10 −1 spec/browser_spec.rb
@@ -111,14 +111,20 @@ def start_server
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
@@ -23,7 +23,7 @@
new_browser.server_port.should_not == browser.server_port
end
end
-
+
it 'forwards stdout to the given IO object' do
io = StringIO.new
new_browser = Capybara::Driver::Webkit::Browser.new(:stdout => io)
@@ -32,4 +32,13 @@
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

0 comments on commit 3eb366e

Please sign in to comment.