Skip to content

Commit e4ea6db

Browse files
committed
use random port
if port 9999 is in use the tests will fail because the port is hardcoded I have added a try/catch with Random. It fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=755320
1 parent cfce4c0 commit e4ea6db

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

test/internals_test.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,18 @@ def af_family_supported(af)
359359
begin
360360
s = Socket.new(af, Socket::SOCK_STREAM, 0)
361361
begin
362-
sa = Socket.pack_sockaddr_in(9999, hosts[af])
363-
s.bind(sa)
362+
tries = 5
363+
begin
364+
sa = Socket.pack_sockaddr_in(Random.rand(1024..65000), hosts[af])
365+
s.bind(sa)
366+
rescue Errno::EADDRINUSE => e
367+
tries -= 1
368+
if tries > 0
369+
retry
370+
else
371+
raise Errno::EADDRINUSE, e
372+
end
373+
end
364374
yield
365375
rescue Errno::EADDRNOTAVAIL
366376
ensure

0 commit comments

Comments
 (0)