1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Revert "Use TCPServer to find available port for server"

This reverts commit a8a4efc379.
This commit is contained in:
Jonas Nicklas 2010-07-09 10:05:30 +02:00
parent a8a4efc379
commit 9fe037d0b4

View file

@ -83,10 +83,8 @@ class Capybara::Server
private
def find_available_port
server = TCPServer.new('127.0.0.1', 0)
@port = server.addr[1]
ensure
server.close if server
@port = 9887
@port += 1 while is_port_open?(@port) and not is_running_on_port?(@port)
end
def is_running_on_port?(tested_port)
@ -99,4 +97,18 @@ private
return false
end
def is_port_open?(tested_port)
Timeout::timeout(1) do
begin
s = TCPSocket.new(host, tested_port)
s.close
return true
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
return false
end
end
rescue Timeout::Error
return false
end
end