Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/ferrum/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,22 @@ def shutdown(wait: true)

begin
close_browser if @client
disconnect
ensure
thread = @process&.stop(wait: wait, grace: Process::Killer::KILL_TIMEOUT)
@process = nil
begin
disconnect
ensure
thread = @process&.stop(wait: wait, grace: Process::Killer::KILL_TIMEOUT)
@process = nil
end
end
thread
end

#
# Closes the page connections and the client connection, leaving the
# browser running, whether Ferrum launched it or connected to it. A
# launched browser stays reachable through {#process}, so it can be
# stopped later with `browser.process.stop` or {#quit}.
# Closes the client connection, leaving the browser running, whether
# Ferrum launched it or connected to it. A launched browser stays
# reachable through {#process}, so it can be stopped later with
# `browser.process.stop` or {#quit}.
#
# @return [nil]
#
Expand Down
19 changes: 19 additions & 0 deletions spec/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,25 @@ def closed_by_peer?(socket)
ensure
launched&.quit
end

it "disconnects and stops the process when Browser.close times out", :launch do
expect_cleanup_when_close_raises(Ferrum::TimeoutError)
end

it "disconnects and stops the process when Browser.close returns an error", :launch do
expect_cleanup_when_close_raises(Ferrum::BrowserError.new("message" => "not allowed"))
end

def expect_cleanup_when_close_raises(error)
browser = Ferrum::Browser.new
allow(browser).to receive(:close).and_raise(error)

expect { browser.shutdown }.to raise_error(error.is_a?(Class) ? error : error.class)
expect(browser.client).to be_nil
expect(browser.process).to be_nil
ensure
browser&.quit
end
end

describe "#restart" do
Expand Down
Loading