summaryrefslogtreecommitdiff
path: root/test/rinda
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-25 18:50:50 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-25 18:50:50 +0000
commita850dc62e939b5dac5062a28e706dbb715f1400a (patch)
tree92b9c240918f9c3d1d71511510a001d9e3b76c5d /test/rinda
parenteaad7bedc9367396d6229dbd42b55194faa39e3b (diff)
Use more general approach to get scope_id see #8159
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rinda')
-rw-r--r--test/rinda/test_rinda.rb44
1 files changed, 22 insertions, 22 deletions
diff --git a/test/rinda/test_rinda.rb b/test/rinda/test_rinda.rb
index 65df228..7791c7e 100644
--- a/test/rinda/test_rinda.rb
+++ b/test/rinda/test_rinda.rb
@@ -525,6 +525,21 @@ class TupleSpaceProxyTest < Test::Unit::TestCase
@server = DRb.primary_server || DRb.start_service
end
+module RingIPv6
+ def prepare_ipv6(r)
+ Socket.ip_address_list.any? do |addrinfo|
+ if /%(?<ifname>\w+)\z/ =~ addrinfo.ip_address
+ next if /\Alo/ =~ ifname
+ _family, _port, _flowinfo, _addr, scope_id =
+ addrinfo.to_sockaddr.unpack("s!S!La16L")
+ r.multicast_interface = scope_id
+ return
+ end
+ end
+ skip 'IPv6 not available'
+ end
+end
+
class TestRingServer < Test::Unit::TestCase
def setup
@@ -588,22 +603,10 @@ class TestRingServer < Test::Unit::TestCase
end
class TestRingFinger < Test::Unit::TestCase
+ include RingIPv6
def setup
@rf = Rinda::RingFinger.new
- ifindex = nil
- 10.times do |i|
- begin
- addrinfo = Addrinfo.udp('ff02::1', Rinda::Ring_PORT)
- soc = Socket.new(addrinfo.pfamily, addrinfo.socktype, addrinfo.protocol)
- soc.setsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_IF,
- [i].pack('I'))
- ifindex = i
- break
- rescue
- end
- end
- @rf.multicast_interface = ifindex
end
def test_make_socket_unicast
@@ -620,26 +623,23 @@ class TestRingFinger < Test::Unit::TestCase
end
def test_make_socket_ipv6_multicast
- skip 'IPv6 not available' unless
- Socket.ip_address_list.any? { |addrinfo| addrinfo.ipv6? }
-
+ prepare_ipv6(@rf)
v6mc = @rf.make_socket('ff02::1')
assert_equal(1, v6mc.getsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_LOOP).int)
assert_equal(1, v6mc.getsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_HOPS).int)
end
- def test_make_socket_multicast_hops
+ 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).int)
+ end
- return unless Socket.ip_address_list.any? { |addrinfo| addrinfo.ipv6? }
-
+ def test_make_socket_ipv6_multicast_hops
+ prepare_ipv6(@rf)
+ @rf.multicast_hops = 2
v6mc = @rf.make_socket('ff02::1')
-
assert_equal(2, v6mc.getsockopt(:IPPROTO_IPV6, :IPV6_MULTICAST_HOPS).int)
end