diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-16 12:29:30 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-16 12:29:30 +0000 |
commit | 50349fd5b718944608bbac2440ac292d1d0ce525 (patch) | |
tree | acd92927d462e9bccd018e9d5b6c8964f322d684 | |
parent | 35da88e634b19750fdba2e4e1dcb0f8a7128e7d1 (diff) | |
download | ruby-50349fd5b718944608bbac2440ac292d1d0ce525.tar.gz |
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
-rw-r--r-- | spec/rubyspec/library/socket/fixtures/classes.rb | 5 | ||||
-rw-r--r-- | spec/rubyspec/library/socket/tcpsocket/shared/new.rb | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/spec/rubyspec/library/socket/fixtures/classes.rb b/spec/rubyspec/library/socket/fixtures/classes.rb index f154330b9d..f6436c7d23 100644 --- a/spec/rubyspec/library/socket/fixtures/classes.rb +++ b/spec/rubyspec/library/socket/fixtures/classes.rb @@ -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 diff --git a/spec/rubyspec/library/socket/tcpsocket/shared/new.rb b/spec/rubyspec/library/socket/tcpsocket/shared/new.rb index b6f557fc18..fed399d80a 100644 --- a/spec/rubyspec/library/socket/tcpsocket/shared/new.rb +++ b/spec/rubyspec/library/socket/tcpsocket/shared/new.rb @@ -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 |