mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Add code to catch server errors at server boot time, and during responsiveness checks
This commit is contained in:
parent
bb7f4b1d68
commit
ab62b27ae1
2 changed files with 22 additions and 2 deletions
|
@ -28,6 +28,7 @@ module Capybara
|
|||
|
||||
def initialize(app)
|
||||
@app = app
|
||||
@server_thread = nil # supress warnings
|
||||
end
|
||||
|
||||
def host
|
||||
|
@ -43,6 +44,8 @@ module Capybara
|
|||
end
|
||||
|
||||
def responsive?
|
||||
return false if @server_thread && @server_thread.join(0)
|
||||
|
||||
res = Net::HTTP.start(host, @port) { |http| http.get('/__identify__') }
|
||||
|
||||
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
|
||||
|
@ -60,11 +63,11 @@ module Capybara
|
|||
@port = Capybara.server_port || find_available_port
|
||||
Capybara::Server.ports[@app.object_id] = @port
|
||||
|
||||
Thread.new do
|
||||
@server_thread = Thread.new do
|
||||
Capybara.server.call(Identify.new(@app), @port)
|
||||
end
|
||||
|
||||
Timeout.timeout(60) { sleep(0.1) until responsive? }
|
||||
Timeout.timeout(60) { @server_thread.join(0.1) until responsive? }
|
||||
end
|
||||
end
|
||||
rescue TimeoutError
|
||||
|
|
|
@ -71,4 +71,21 @@ describe Capybara::Server do
|
|||
@server1a.port.should == @server1b.port
|
||||
@server2a.port.should == @server2b.port
|
||||
end
|
||||
|
||||
it "should raise server errors when the server errors before the timeout" do
|
||||
begin
|
||||
Capybara.server do
|
||||
sleep 0.1
|
||||
raise 'kaboom'
|
||||
end
|
||||
|
||||
proc do
|
||||
Capybara::Server.new(proc {|e|}).boot
|
||||
end.should raise_error(RuntimeError, 'kaboom')
|
||||
ensure
|
||||
# TODO refactor out the defaults so it's reliant on unset state instead of
|
||||
# a one-time call in capybara.rb
|
||||
Capybara.server {|app, port| Capybara.run_default_server(app, port)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue