mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test/socket/test_socket.rb (test_timestamp): retry send
I theorize there can be UDP packet loss even over loopback if the kernel is under memory pressure. Retry sending periodically until recvmsg succeeds. i[ruby-core:87842] [Bug #14898] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7387c08373
commit
eb78bedab7
1 changed files with 18 additions and 4 deletions
|
@ -464,10 +464,24 @@ 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)
|
||||
s2.send "a", 0, s1.local_address
|
||||
msg, _, _, stamp = s1.recvmsg
|
||||
assert_equal("a", msg)
|
||||
assert(stamp.cmsg_is?(:SOCKET, :TIMESTAMP))
|
||||
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
|
||||
}
|
||||
}
|
||||
t2 = Time.now.strftime("%Y-%m-%d")
|
||||
|
|
Loading…
Reference in a new issue