ruby-changes:45074
From: nobu <ko1@a...>
Date: Thu, 22 Dec 2016 11:00:07 +0900 (JST)
Subject: [ruby-changes:45074] nobu:r57147 (trunk): test_rinda.rb: ipv6_mc
nobu 2016-12-22 11:00:02 +0900 (Thu, 22 Dec 2016) New Revision: 57147 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57147 Log: test_rinda.rb: ipv6_mc * test/rinda/test_rinda.rb (RingIPv6#ipv6_mc): extract IPv6 multicast setup and cleanup, and ignore ENETDOWN. Modified files: trunk/test/rinda/test_rinda.rb Index: test/rinda/test_rinda.rb =================================================================== --- test/rinda/test_rinda.rb (revision 57146) +++ test/rinda/test_rinda.rb (revision 57147) @@ -552,6 +552,26 @@ module RingIPv6 https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L552 end skip 'IPv6 not available' end + + def ipv6_mc(rf, hops = nil) + ifaddr = prepare_ipv6(rf) + rf.multicast_hops = hops if hops + begin + v6mc = rf.make_socket("ff02::1") + rescue Errno::EINVAL + # somehow Debian 6.0.7 needs ifname + v6mc = rf.make_socket("ff02::1%#{ifaddr.name}") + rescue Errno::EADDRNOTAVAIL + return # IPv6 address for multicast not available + rescue Errno::ENETDOWN + return # Network is down + end + begin + yield v6mc + ensure + v6mc.close + end + end end class TestRingServer < Test::Unit::TestCase @@ -788,20 +808,10 @@ class TestRingFinger < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L808 end def test_make_socket_ipv6_multicast - ifaddr = prepare_ipv6(@rf) - begin - v6mc = @rf.make_socket("ff02::1") - rescue Errno::EINVAL - # somehow Debian 6.0.7 needs ifname - v6mc = @rf.make_socket("ff02::1%#{ifaddr.name}") - rescue Errno::EADDRNOTAVAIL - return # IPv6 address for multicast not available + ipv6_mc(@rf) do |v6mc| + assert_equal(1, v6mc.getsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_LOOP).int) + assert_equal(1, v6mc.getsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_HOPS).int) end - - assert_equal(1, v6mc.getsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_LOOP).int) - assert_equal(1, v6mc.getsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_HOPS).int) - ensure - v6mc.close if v6mc end def test_make_socket_ipv4_multicast_hops @@ -813,19 +823,9 @@ class TestRingFinger < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/rinda/test_rinda.rb#L823 end def test_make_socket_ipv6_multicast_hops - ifaddr = prepare_ipv6(@rf) - @rf.multicast_hops = 2 - begin - v6mc = @rf.make_socket("ff02::1") - rescue Errno::EINVAL - # somehow Debian 6.0.7 needs ifname - v6mc = @rf.make_socket("ff02::1%#{ifaddr.name}") - rescue Errno::EADDRNOTAVAIL - return # IPv6 address for multicast not available + ipv6_mc(@rf, 2) do |v6mc| + assert_equal(2, v6mc.getsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_HOPS).int) end - assert_equal(2, v6mc.getsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_HOPS).int) - ensure - v6mc.close if v6mc end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/