ruby-changes:51942
From: normal <ko1@a...>
Date: Thu, 2 Aug 2018 15:09:44 +0900 (JST)
Subject: [ruby-changes:51942] normal:r64157 (trunk): test/socket/test_socket.rb (test_timestampns): retry send
normal 2018-08-02 15:09:38 +0900 (Thu, 02 Aug 2018) New Revision: 64157 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64157 Log: 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] Modified files: trunk/test/socket/test_socket.rb Index: test/socket/test_socket.rb =================================================================== --- test/socket/test_socket.rb (revision 64156) +++ test/socket/test_socket.rb (revision 64157) @@ -456,6 +456,33 @@ class TestSocket < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/socket/test_socket.rb#L456 } 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 https://github.com/ruby/ruby/blob/trunk/test/socket/test_socket.rb#L491 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 https://github.com/ruby/ruby/blob/trunk/test/socket/test_socket.rb#L511 # 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/