[前][次][番号順一覧][スレッド一覧]

ruby-changes:51660

From: normal <ko1@a...>
Date: Sat, 7 Jul 2018 14:34:09 +0900 (JST)
Subject: [ruby-changes:51660] normal:r63872 (trunk): test/socket/test_socket.rb (test_timestamp): retry send

normal	2018-07-07 14:34:03 +0900 (Sat, 07 Jul 2018)

  New Revision: 63872

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63872

  Log:
    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]

  Modified files:
    trunk/test/socket/test_socket.rb
Index: test/socket/test_socket.rb
===================================================================
--- test/socket/test_socket.rb	(revision 63871)
+++ test/socket/test_socket.rb	(revision 63872)
@@ -464,10 +464,24 @@ class TestSocket < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/socket/test_socket.rb#L464
     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")

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]