summaryrefslogtreecommitdiff
path: root/test/socket
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-07 05:34:03 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-07 05:34:03 +0000
commiteb78bedab73136cf78df1db6fb77b130ca39255f (patch)
tree3619dff8927b241df6f45368f3cb2c66440abf14 /test/socket
parent7387c08373a9421356da2581b1035903ac0a301a (diff)
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
Diffstat (limited to 'test/socket')
-rw-r--r--test/socket/test_socket.rb22
1 files changed, 18 insertions, 4 deletions
diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb
index 126f789492..10549383c9 100644
--- a/test/socket/test_socket.rb
+++ b/test/socket/test_socket.rb
@@ -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")