mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Use a reserved port to test for a non-existing TCP server
* Avoids a race between finding an available port and another process starting a server on it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
35da88e634
commit
50349fd5b7
2 changed files with 6 additions and 1 deletions
|
@ -46,6 +46,11 @@ module SocketSpecs
|
|||
find_available_port
|
||||
end
|
||||
|
||||
def self.reserved_unused_port
|
||||
# https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
|
||||
0
|
||||
end
|
||||
|
||||
def self.sockaddr_in(port, host)
|
||||
Socket::SockAddr_In.new(Socket.sockaddr_in(port, host))
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ describe :tcpsocket_new, shared: true do
|
|||
|
||||
it "refuses the connection when there is no server to connect to" do
|
||||
lambda do
|
||||
TCPSocket.send(@method, SocketSpecs.hostname, SocketSpecs.local_port)
|
||||
TCPSocket.send(@method, SocketSpecs.hostname, SocketSpecs.reserved_unused_port)
|
||||
end.should raise_error(Errno::ECONNREFUSED)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue