Skip to content

Commit

Permalink
Remove uses of Timeout.timeout from Server (teamcapybara#2016)
Browse files Browse the repository at this point in the history
* Don't use Timeout.timeout in Server#wait_for_pending_requests

I expect this to be equivalent since it rases the same error and has the
same pattern of sleeps.

* Don't use Timeout.timeout in Server#boot

I expect this to be equivalent since it rases the same error and has the
same pattern of sleeps.

I don't know of any problems caused by using timeout here, instead I've
converted this for consistency and so that that there are no longer any
uses of `Timeout.timeout` within the codebase.
  • Loading branch information
zetter authored and twalpole committed Apr 18, 2018
1 parent 431482b commit 71cd062
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/capybara/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ def responsive?
end

def wait_for_pending_requests
Timeout.timeout(60) { sleep(0.01) while pending_requests? }
rescue Timeout::Error
raise "Requests did not finish in 60 seconds"
start_time = Capybara::Helpers.monotonic_time
while pending_requests?
if (Capybara::Helpers.monotonic_time - start_time) > 60
raise "Requests did not finish in 60 seconds"
end
sleep 0.01
end
end

def boot
Expand All @@ -103,11 +107,15 @@ def boot
Capybara.server.call(middleware, port, host)
end

Timeout.timeout(60) { @server_thread.join(0.1) until responsive? }
start_time = Capybara::Helpers.monotonic_time
until responsive?
if (Capybara::Helpers.monotonic_time - start_time) > 60
raise "Rack application timed out during boot"
end
@server_thread.join(0.1)
end
end
rescue Timeout::Error
raise "Rack application timed out during boot"
else

self
end

Expand Down

0 comments on commit 71cd062

Please sign in to comment.