Skip to content

Commit

Permalink
Handle situations where IPv4 multicast is not available
Browse files Browse the repository at this point in the history
Fixes [Bug #13864]
  • Loading branch information
jeremyevans committed Aug 14, 2022
1 parent 97b8c5a commit 3cd620f
Showing 1 changed file with 41 additions and 30 deletions.
71 changes: 41 additions & 30 deletions test/rinda/test_rinda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,22 @@ def test_take_bug_8215
end
end

module RingIPv4
def ipv4_mc(rf)
begin
v4mc = rf.make_socket('239.0.0.1')
rescue Errno::ENETUNREACH, Errno::ENOBUFS, Errno::ENODEV
omit 'IPv4 multicast not available'
end

begin
yield v4mc
ensure
v4mc.close
end
end
end

module RingIPv6
def prepare_ipv6(r)
begin
Expand Down Expand Up @@ -625,6 +641,7 @@ def ipv6_mc(rf, hops = nil)
end

class TestRingServer < Test::Unit::TestCase
include RingIPv4

def setup
@port = Rinda::Ring_PORT
Expand Down Expand Up @@ -697,27 +714,23 @@ def test_make_socket_unicast
end

def test_make_socket_ipv4_multicast
begin
v4mc = @rs.make_socket('239.0.0.1')
rescue Errno::ENOBUFS => e
omit "Missing multicast support in OS: #{e.message}"
end

begin
if Socket.const_defined?(:SO_REUSEPORT) then
assert(v4mc.getsockopt(:SOCKET, :SO_REUSEPORT).bool)
else
assert(v4mc.getsockopt(:SOCKET, :SO_REUSEADDR).bool)
end
rescue TypeError
if /aix/ =~ RUBY_PLATFORM
omit "Known bug in getsockopt(2) on AIX"
ipv4_mc(@rs) do |v4mc|
begin
if Socket.const_defined?(:SO_REUSEPORT) then
assert(v4mc.getsockopt(:SOCKET, :SO_REUSEPORT).bool)
else
assert(v4mc.getsockopt(:SOCKET, :SO_REUSEADDR).bool)
end
rescue TypeError
if /aix/ =~ RUBY_PLATFORM
omit "Known bug in getsockopt(2) on AIX"
end
raise $!
end
raise $!
end

assert_equal('0.0.0.0', v4mc.local_address.ip_address)
assert_equal(@port, v4mc.local_address.ip_port)
assert_equal('0.0.0.0', v4mc.local_address.ip_address)
assert_equal(@port, v4mc.local_address.ip_port)
end
end

def test_make_socket_ipv6_multicast
Expand Down Expand Up @@ -746,7 +759,7 @@ def test_ring_server_ipv4_multicast
@rs.shutdown
begin
@rs = Rinda::RingServer.new(@ts, [['239.0.0.1', '0.0.0.0']], @port)
rescue Errno::ENOBUFS => e
rescue Errno::ENOBUFS, Errno::ENODEV => e
omit "Missing multicast support in OS: #{e.message}"
end

Expand Down Expand Up @@ -848,6 +861,7 @@ def wait_for(n)

class TestRingFinger < Test::Unit::TestCase
include RingIPv6
include RingIPv4

def setup
@rf = Rinda::RingFinger.new
Expand All @@ -867,12 +881,10 @@ def test_make_socket_unicast
end

def test_make_socket_ipv4_multicast
v4mc = @rf.make_socket('239.0.0.1')

assert_equal(1, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_LOOP).ipv4_multicast_loop)
assert_equal(1, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL).ipv4_multicast_ttl)
ensure
v4mc.close if v4mc
ipv4_mc(@rf) do |v4mc|
assert_equal(1, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_LOOP).ipv4_multicast_loop)
assert_equal(1, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL).ipv4_multicast_ttl)
end
end

def test_make_socket_ipv6_multicast
Expand All @@ -884,10 +896,9 @@ def test_make_socket_ipv6_multicast

def test_make_socket_ipv4_multicast_hops
@rf.multicast_hops = 2
v4mc = @rf.make_socket('239.0.0.1')
assert_equal(2, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL).ipv4_multicast_ttl)
ensure
v4mc.close if v4mc
ipv4_mc(@rf) do |v4mc|
assert_equal(2, v4mc.getsockopt(:IPPROTO_IP, :IP_MULTICAST_TTL).ipv4_multicast_ttl)
end
end

def test_make_socket_ipv6_multicast_hops
Expand Down

0 comments on commit 3cd620f

Please sign in to comment.