about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-02-26 14:20:37 -0800
committerEric Wong <normalperson@yhbt.net>2011-02-26 14:20:37 -0800
commitb9119424bdd41e417afae354329e9b6d298baff4 (patch)
treeb3dc3fefbdcc7bdfd89df3ef6c21ddf64f8ba959
parent62f706a496eba0bc581fb2c277fed2dc29f60eb0 (diff)
downloadruby_io_splice-b9119424bdd41e417afae354329e9b6d298baff4.tar.gz
It's wholly unnecessary when we don't do exec() for other
processes.
-rw-r--r--test/test_io_splice.rb43
1 files changed, 6 insertions, 37 deletions
diff --git a/test/test_io_splice.rb b/test/test_io_splice.rb
index bcb5935..c21b28a 100644
--- a/test/test_io_splice.rb
+++ b/test/test_io_splice.rb
@@ -7,37 +7,6 @@ require 'timeout'
 $-w = true
 require 'io/splice'
 
-# unused_port provides an unused port on +addr+ usable for TCP that is
-# guaranteed to be unused across all unicorn builds on that system.  It
-# prevents race conditions by using a lock file other unicorn builds
-# will see.  This is required if you perform several builds in parallel
-# with a continuous integration system or run tests in parallel via
-# gmake.  This is NOT guaranteed to be race-free if you run other
-# processes that bind to random ports for testing (but the window
-# for a race condition is very small).
-def unused_port(addr = '127.0.0.1')
-  retries = 100
-  base = 5000
-  port = sock = nil
-  begin
-    sock = TCPServer.new(addr, 0)
-    port = sock.addr[1]
-
-    # since we'll end up closing the random port we just got, there's a race
-    # condition could allow the random port we just chose to reselect itself
-    # when running tests in parallel with gmake.  Create a lock file while
-    # we have the port here to ensure that does not happen .
-    lock_path = "#{Dir::tmpdir}/unicorn_test.#{addr}:#{port}.lock"
-    File.open(lock_path, File::WRONLY|File::CREAT|File::EXCL, 0600).close
-    at_exit { File.unlink(lock_path) rescue nil }
-  rescue Errno::EEXIST
-    sock.close rescue nil
-    retry
-  end
-  sock.close rescue nil
-  port
-end
-
 class Test_IO_Splice < Test::Unit::TestCase
 
   def test_splice
@@ -162,8 +131,8 @@ class Test_IO_Splice < Test::Unit::TestCase
   end
 
   def test_splice_nonblock_socket
-    port = unused_port
-    server = TCPServer.new('127.0.0.1', port)
+    server = TCPServer.new('127.0.0.1', 0)
+    port = server.addr[1]
     rp, wp = IO.pipe
     rs = TCPSocket.new('127.0.0.1', port)
     rs.nonblock = true
@@ -351,8 +320,8 @@ class Test_IO_Splice < Test::Unit::TestCase
   end
 
   def test_copy_stream_nonblock_src
-    port = unused_port
-    server = TCPServer.new('127.0.0.1', port)
+    server = TCPServer.new('127.0.0.1', 0)
+    port = server.addr[1]
     rp, wp = IO.pipe
     rs = TCPSocket.new('127.0.0.1', port)
     rs.nonblock = true
@@ -366,8 +335,8 @@ class Test_IO_Splice < Test::Unit::TestCase
   end
 
   def test_copy_stream_nonblock_dst
-    port = unused_port
-    server = TCPServer.new('127.0.0.1', port)
+    server = TCPServer.new('127.0.0.1', 0)
+    port = server.addr[1]
     rp, wp = IO.pipe
     rs = TCPSocket.new('127.0.0.1', port)
     rs.nonblock = true