ruby-changes:72930
From: Jeremy <ko1@a...>
Date: Mon, 15 Aug 2022 14:12:07 +0900 (JST)
Subject: [ruby-changes:72930] 89aa09afaf (master): [ruby/rinda] Handle situations where IPv4 multicast is not available
https://git.ruby-lang.org/ruby.git/commit/?id=89aa09afaf From 89aa09afaf77920fd748aefaba99fe4b0f19e684 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Fri, 6 Aug 2021 15:36:33 -0700 Subject: [ruby/rinda] Handle situations where IPv4 multicast is not available Fixes [Bug #13864] https://github.com/ruby/rinda/commit/3cd620f38c --- test/rinda/test_rinda.rb | 71 ++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/test/rinda/test_rinda.rb b/test/rinda/test_rinda.rb index d8340e0fc4..dbe414b783 100644 --- a/test/rinda/test_rinda.rb +++ b/test/rinda/test_rinda.rb @@ -583,6 +583,22 @@ class TupleSpaceProxyTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L583 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 @@ -625,6 +641,7 @@ module RingIPv6 https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L641 end class TestRingServer < Test::Unit::TestCase + include RingIPv4 def setup @port = Rinda::Ring_PORT @@ -697,27 +714,23 @@ class TestRingServer < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L714 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 @@ -746,7 +759,7 @@ class TestRingServer < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L759 @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 @@ -848,6 +861,7 @@ end https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L861 class TestRingFinger < Test::Unit::TestCase include RingIPv6 + include RingIPv4 def setup @rf = Rinda::RingFinger.new @@ -867,12 +881,10 @@ class TestRingFinger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L881 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 @@ -884,10 +896,9 @@ class TestRingFinger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L896 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 -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/