1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
Description: use random port for tests
Author: Jonas Genannt
Forwarded: yes
Bug: https://github.com/redis/redis-rb/pull/455
diff --git a/test/internals_test.rb b/test/internals_test.rb
index 0c0f7bc..7e3d61d 100644
--- a/test/internals_test.rb
+++ b/test/internals_test.rb
@@ -375,8 +375,18 @@ class TestInternals < Test::Unit::TestCase
begin
s = Socket.new(af, Socket::SOCK_STREAM, 0)
begin
- sa = Socket.pack_sockaddr_in(9999, hosts[af])
- s.bind(sa)
+ tries = 5
+ begin
+ sa = Socket.pack_sockaddr_in(Random.rand(1024..65000), hosts[af])
+ s.bind(sa)
+ rescue Errno::EADDRINUSE => e
+ tries -= 1
+ if tries > 0
+ retry
+ else
+ raise Errno::EADDRINUSE, e
+ end
+ end
yield
rescue Errno::EADDRNOTAVAIL
ensure
|