From: SASADA Koichi Date: 2017-05-28T10:22:38+09:00 Subject: [ruby-core:81427] Fwd: [ruby-changes:46809] normal:r58924 (trunk): test for IO.copy_stream CPU usage (r58534) Hi, My CI reports many failures on this test_copy_stream_no_busy_wait. http://ci.rvm.jp/ On Debian (I forget the version, but using Kernel 3.2.0-4-amd64): http://ci.rvm.jp/results/trunk-test@sasada-8core (search "NG") https://gist.github.com/anonymous/26dc659e34320b40d27591b4f91f51fe#file-brlog-trunk-test-20170528-100249-L655 On Ubuntu14: http://ci.rvm.jp/results/trunk-test@frontier (search "NG") https://gist.github.com/ko1/aa95d84417fa79284a0613c17729e4e7#file-brlog-trunk-test-20170528-041307-L647 On Ubuntu16: http://ci.rvm.jp/results/trunk@P895 http://ci.rvm.jp/results/trunk-test@ruby-sky3 (search "NG") https://gist.github.com/anonymous/316832cba0307d0344434f144a292e59#file-brlog-trunk-20170528-084148-L409 https://gist.github.com/anonymous/8da1d0b0a7b3de10b9b4fe6bd24658ea#file-brlog-trunk-20170528-023739-L397 https://gist.github.com/anonymous/6144a5e1a54ba317f47326dd465492df#file-brlog-trunk-20170527-235730-L373 On raspi: http://ci.rvm.jp/results/trunk@pi2 (search "NG") https://gist.github.com/anonymous/c089332f436bd0a0ecf8b4a0113e01ea#file-brlog-trunk-20170528-004604-L375 Is it intentional or not? Thanks, Koichi -------- Forwarded Message -------- Subject: [ruby-changes:46809] normal:r58924 (trunk): test for IO.copy_stream CPU usage (r58534) Date: Sat, 27 May 2017 16:23:05 +0900 (JST) From: normal Reply-To: ruby-changes@quickml.atdot.net To: ruby-changes@quickml.atdot.net normal 2017-05-27 16:23:02 +0900 (Sat, 27 May 2017) New Revision: 58924 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58924 Log: test for IO.copy_stream CPU usage (r58534) I'm likely to make similar mistakes in the future when working on Fiber auto-scheduling. Start adding assertions for existing code, first. * test/ruby/test_io.rb (test_copy_stream_no_busy_wait): added * test/lib/test/unit/assertions.rb (assert_cpu_usage_low): added Modified files: trunk/test/lib/test/unit/assertions.rb trunk/test/ruby/test_io.rb Index: test/lib/test/unit/assertions.rb =================================================================== --- test/lib/test/unit/assertions.rb (revision 58923) +++ test/lib/test/unit/assertions.rb (revision 58924) @@ -715,6 +715,13 @@ eom https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit/assertions.rb#L715 skip end + def assert_cpu_usage_low(msg = nil, pct: 0.005) + require 'benchmark' + tms = Benchmark.measure(msg || '') { yield } + max = pct * tms.real + assert_operator tms.total, :<=, max, msg + end + def assert_is_minus_zero(f) assert(1.0/f == -Float::INFINITY, "#{f} is not -0.0") end Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 58923) +++ test/ruby/test_io.rb (revision 58924) @@ -532,6 +532,18 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L532 end if have_nonblock? + def test_copy_stream_no_busy_wait + IO.pipe do |r,w| + r.nonblock = true + assert_cpu_usage_low('r58534 [ruby-core:80969] [Backport #13533]') do + th = Thread.new { IO.copy_stream(r, IO::NULL) } + sleep 0.1 + w.close + th.join + end + end + end + def test_copy_stream_pipe_nonblock mkcdtmpdir { with_read_pipe("abc") {|r1| -- ML: ruby-changes@quickml.atdot.net Info: http://www.atdot.net/~ko1/quickml/ Unsubscribe: