Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Only allow process that started server to shut it down.
  • Loading branch information
halogenandtoast committed Oct 14, 2011
1 parent b4708b2 commit 3eb366e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lib/capybara/driver/webkit/browser.rb
Expand Up @@ -111,14 +111,20 @@ def start_server


def fork_server def fork_server
server_path = File.expand_path("../../../../../bin/webkit_server", __FILE__) server_path = File.expand_path("../../../../../bin/webkit_server", __FILE__)

pipe, @pid = server_pipe_and_pid(server_path) pipe, @pid = server_pipe_and_pid(server_path)

register_shutdown_hook
at_exit { Process.kill("INT", @pid) }

pipe pipe
end 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) def server_pipe_and_pid(server_path)
pipe = IO.popen(server_path) pipe = IO.popen(server_path)
[pipe, pipe.pid] [pipe, pipe.pid]
Expand Down
11 changes: 10 additions & 1 deletion spec/browser_spec.rb
Expand Up @@ -23,7 +23,7 @@
new_browser.server_port.should_not == browser.server_port new_browser.server_port.should_not == browser.server_port
end end
end end

it 'forwards stdout to the given IO object' do it 'forwards stdout to the given IO object' do
io = StringIO.new io = StringIO.new
new_browser = Capybara::Driver::Webkit::Browser.new(:stdout => io) new_browser = Capybara::Driver::Webkit::Browser.new(:stdout => io)
Expand All @@ -32,4 +32,13 @@
io.string.should == "hello world\n" io.string.should == "hello world\n"
end 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 end

0 comments on commit 3eb366e

Please sign in to comment.