diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-02-05 03:27:54 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-02-05 03:27:54 -0800 |
commit | 31f77b2a01f69956b034d35a7f12038947b6bdbc (patch) | |
tree | 365e8817bdbc4a6d659ac53fc3318a68b9533ad6 | |
parent | cba967458df157f3e4aa2dc885eb87013bece175 (diff) | |
download | ruby_io_splice-31f77b2a01f69956b034d35a7f12038947b6bdbc.tar.gz |
Duh!
-rw-r--r-- | test/test_io_splice.rb | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/test/test_io_splice.rb b/test/test_io_splice.rb index a00552e..28d3dae 100644 --- a/test/test_io_splice.rb +++ b/test/test_io_splice.rb @@ -20,26 +20,15 @@ def unused_port(addr = '127.0.0.1') base = 5000 port = sock = nil begin - begin - port = base + rand(32768 - base) - while port == 8080 - 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 + 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" - lock = File.open(lock_path, File::WRONLY|File::CREAT|File::EXCL, 0600) + 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 |