summaryrefslogtreecommitdiff
path: root/test/io/wait/test_io_wait.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-12-24 15:47:59 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-12-24 15:48:08 +0900
commit81504e83e72bf125476528e5f119604d9697f682 (patch)
tree86e4b7dabda98b13d2308f0877e8fc75b3cb418f /test/io/wait/test_io_wait.rb
parent47ad57f2450251f47b3f8e1f744d782269bbcdeb (diff)
Synchronize with a Queue instead of sleeping
Diffstat (limited to 'test/io/wait/test_io_wait.rb')
-rw-r--r--test/io/wait/test_io_wait.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/test/io/wait/test_io_wait.rb b/test/io/wait/test_io_wait.rb
index 50c06976b8c..4003f2aff10 100644
--- a/test/io/wait/test_io_wait.rb
+++ b/test/io/wait/test_io_wait.rb
@@ -63,16 +63,20 @@ class TestIOWait < Test::Unit::TestCase
end
def test_wait_forever
- th = Thread.new { sleep 0.01; @w.syswrite "." }
+ q = Thread::Queue.new
+ th = Thread.new { q.pop; @w.syswrite "." }
+ q.push(true)
assert_equal @r, @r.wait
ensure
th.join
end
def test_wait_eof
- th = Thread.new { sleep 0.01; @w.close }
+ q = Thread::Queue.new
+ th = Thread.new { q.pop; @w.close }
ret = nil
assert_nothing_raised(Timeout::Error) do
+ q.push(true)
Timeout.timeout(0.1) { ret = @r.wait }
end
assert_equal @r, ret
@@ -94,16 +98,20 @@ class TestIOWait < Test::Unit::TestCase
end
def test_wait_readable_forever
- th = Thread.new { sleep 0.01; @w.syswrite "." }
+ q = Thread::Queue.new
+ th = Thread.new { q.pop; @w.syswrite "." }
+ q.push(true)
assert_equal @r, @r.wait_readable
ensure
th.join
end
def test_wait_readable_eof
- th = Thread.new { sleep 0.01; @w.close }
+ q = Thread::Queue.new
+ th = Thread.new { q.pop; @w.close }
ret = nil
assert_nothing_raised(Timeout::Error) do
+ q.push(true)
Timeout.timeout(0.1) { ret = @r.wait_readable }
end
assert_equal @r, ret