From 71dca4b60dafa87601df4ded2847411bb5b598da Mon Sep 17 00:00:00 2001 From: normal Date: Sat, 27 May 2017 07:23:02 +0000 Subject: 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58924 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 2b82470b8c..5d14aae601 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -532,6 +532,18 @@ class TestIO < Test::Unit::TestCase 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| -- cgit v1.2.3