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

ruby-changes:59441

From: Nobuyoshi <ko1@a...>
Date: Tue, 24 Dec 2019 16:13:11 +0900 (JST)
Subject: [ruby-changes:59441] 81504e83e7 (master): Synchronize with a Queue instead of sleeping

https://git.ruby-lang.org/ruby.git/commit/?id=81504e83e7

From 81504e83e72bf125476528e5f119604d9697f682 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 24 Dec 2019 15:47:59 +0900
Subject: Synchronize with a Queue instead of sleeping


diff --git a/test/io/wait/test_io_wait.rb b/test/io/wait/test_io_wait.rb
index 50c0697..4003f2a 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 https://github.com/ruby/ruby/blob/trunk/test/io/wait/test_io_wait.rb#L63
   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 https://github.com/ruby/ruby/blob/trunk/test/io/wait/test_io_wait.rb#L98
   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
-- 
cgit v0.10.2


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

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