ruby-changes:46632
From: eregon <ko1@a...>
Date: Tue, 16 May 2017 21:29:36 +0900 (JST)
Subject: [ruby-changes:46632] eregon:r58747 (trunk): Use a reserved port to test for a non-existing TCP server
eregon 2017-05-16 21:29:30 +0900 (Tue, 16 May 2017) New Revision: 58747 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58747 Log: 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. Modified files: trunk/spec/rubyspec/library/socket/fixtures/classes.rb trunk/spec/rubyspec/library/socket/tcpsocket/shared/new.rb Index: spec/rubyspec/library/socket/fixtures/classes.rb =================================================================== --- spec/rubyspec/library/socket/fixtures/classes.rb (revision 58746) +++ spec/rubyspec/library/socket/fixtures/classes.rb (revision 58747) @@ -46,6 +46,11 @@ module SocketSpecs https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/library/socket/fixtures/classes.rb#L46 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 Index: spec/rubyspec/library/socket/tcpsocket/shared/new.rb =================================================================== --- spec/rubyspec/library/socket/tcpsocket/shared/new.rb (revision 58746) +++ spec/rubyspec/library/socket/tcpsocket/shared/new.rb (revision 58747) @@ -8,7 +8,7 @@ describe :tcpsocket_new, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/library/socket/tcpsocket/shared/new.rb#L8 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/