mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test/socket/test_socket.rb (test_timestampns): retry send
It looks like we need to retry test_timestampns in addition to test_timestamp; so share some code while we're at it. cf. http://ci.rvm.jp/results/trunk-test@frontier/1153126 [ruby-core:88104] [Bug #14898] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e62214be87
commit
12f11714c2
1 changed files with 29 additions and 30 deletions
|
@ -456,6 +456,33 @@ class TestSocket < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def timestamp_retry_rw(s1, s2, t1, type)
|
||||
IO.pipe do |r,w|
|
||||
# UDP may not be reliable, keep sending until recvmsg returns:
|
||||
th = Thread.new do
|
||||
n = 0
|
||||
begin
|
||||
s2.send("a", 0, s1.local_address)
|
||||
n += 1
|
||||
end while IO.select([r], nil, nil, 0.1).nil?
|
||||
n
|
||||
end
|
||||
msg, _, _, stamp = s1.recvmsg
|
||||
assert_equal("a", msg)
|
||||
assert(stamp.cmsg_is?(:SOCKET, type))
|
||||
w.close # stop th
|
||||
n = th.value
|
||||
n > 1 and
|
||||
warn "UDP packet loss for #{type} over loopback, #{n} tries needed"
|
||||
t2 = Time.now.strftime("%Y-%m-%d")
|
||||
pat = Regexp.union([t1, t2].uniq)
|
||||
assert_match(pat, stamp.inspect)
|
||||
t = stamp.timestamp
|
||||
assert_match(pat, t.strftime("%Y-%m-%d"))
|
||||
stamp
|
||||
end
|
||||
end
|
||||
|
||||
def test_timestamp
|
||||
return if /linux|freebsd|netbsd|openbsd|solaris|darwin/ !~ RUBY_PLATFORM
|
||||
return if !defined?(Socket::AncillaryData) || !defined?(Socket::SO_TIMESTAMP)
|
||||
|
@ -464,31 +491,10 @@ class TestSocket < Test::Unit::TestCase
|
|||
Addrinfo.udp("127.0.0.1", 0).bind {|s1|
|
||||
Addrinfo.udp("127.0.0.1", 0).bind {|s2|
|
||||
s1.setsockopt(:SOCKET, :TIMESTAMP, true)
|
||||
IO.pipe do |r,w|
|
||||
# UDP may not be reliable, keep sending until recvmsg returns:
|
||||
th = Thread.new do
|
||||
n = 0
|
||||
begin
|
||||
s2.send("a", 0, s1.local_address)
|
||||
n += 1
|
||||
end while IO.select([r], nil, nil, 0.1).nil?
|
||||
n
|
||||
end
|
||||
|
||||
msg, _, _, stamp = s1.recvmsg
|
||||
w.close # stop th
|
||||
assert_equal("a", msg)
|
||||
assert(stamp.cmsg_is?(:SOCKET, :TIMESTAMP))
|
||||
n = th.value
|
||||
warn "UDP packet loss over loopback, #{n} tries needed" if n > 1
|
||||
end
|
||||
stamp = timestamp_retry_rw(s1, s2, t1, :TIMESTAMP)
|
||||
}
|
||||
}
|
||||
t2 = Time.now.strftime("%Y-%m-%d")
|
||||
pat = Regexp.union([t1, t2].uniq)
|
||||
assert_match(pat, stamp.inspect)
|
||||
t = stamp.timestamp
|
||||
assert_match(pat, t.strftime("%Y-%m-%d"))
|
||||
pat = /\.#{"%06d" % t.usec}/
|
||||
assert_match(pat, stamp.inspect)
|
||||
end
|
||||
|
@ -505,17 +511,10 @@ class TestSocket < Test::Unit::TestCase
|
|||
# SO_TIMESTAMPNS is available since Linux 2.6.22
|
||||
return
|
||||
end
|
||||
s2.send "a", 0, s1.local_address
|
||||
msg, _, _, stamp = s1.recvmsg
|
||||
assert_equal("a", msg)
|
||||
assert(stamp.cmsg_is?(:SOCKET, :TIMESTAMPNS))
|
||||
stamp = timestamp_retry_rw(s1, s2, t1, :TIMESTAMPNS)
|
||||
}
|
||||
}
|
||||
t2 = Time.now.strftime("%Y-%m-%d")
|
||||
pat = Regexp.union([t1, t2].uniq)
|
||||
assert_match(pat, stamp.inspect)
|
||||
t = stamp.timestamp
|
||||
assert_match(pat, t.strftime("%Y-%m-%d"))
|
||||
pat = /\.#{"%09d" % t.nsec}/
|
||||
assert_match(pat, stamp.inspect)
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue