about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-02-10 13:41:32 -0800
committerEric Wong <normalperson@yhbt.net>2011-02-10 13:41:32 -0800
commit4cfb64f10784498b9625bbbd3364231710bc7c36 (patch)
tree6e18cb4f6c3f9cd7ae148fef78240a5075ed757c /test
parent6dd90cb902f43b32b0db204484d5e3df79ec0d0c (diff)
downloadunicorn-4cfb64f10784498b9625bbbd3364231710bc7c36.tar.gz
This causes conflicts with ports clients may use in
the ephemeral range since those do not hold FS locks.

This reverts commit e597e594ad88dc02d70f7d3521d0d3bdc23739bb.

Conflicts:

	test/test_helper.rb
Diffstat (limited to 'test')
-rw-r--r--test/test_helper.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/test/test_helper.rb b/test/test_helper.rb
index d9ff90c..92195e6 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -100,10 +100,23 @@ end
 # for a race condition is very small).  You may also set UNICORN_TEST_ADDR
 # to override the default test address (127.0.0.1).
 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]
+    begin
+      port = base + rand(32768 - base)
+      while port == Unicorn::Const::DEFAULT_PORT
+        port = base + rand(32768 - base)
+      end
+
+      sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
+      sock.bind(Socket.pack_sockaddr_in(port, addr))
+      sock.listen(5)
+    rescue Errno::EADDRINUSE, Errno::EACCES
+      sock.close rescue nil
+      retry if (retries -= 1) >= 0
+    end
 
     # 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