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

ruby-changes:44210

From: nobu <ko1@a...>
Date: Wed, 28 Sep 2016 23:12:42 +0900 (JST)
Subject: [ruby-changes:44210] nobu:r56283 (trunk): test_pstore.rb: use queues

nobu	2016-09-28 23:12:33 +0900 (Wed, 28 Sep 2016)

  New Revision: 56283

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56283

  Log:
    test_pstore.rb: use queues
    
    * test/test_pstore.rb (PStoreTest#test_thread_safe): handshake by
      queues, and reduce sleeping time.

  Modified files:
    trunk/test/test_pstore.rb
Index: test/test_pstore.rb
===================================================================
--- test/test_pstore.rb	(revision 56282)
+++ test/test_pstore.rb	(revision 56283)
@@ -75,34 +75,39 @@ class PStoreTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_pstore.rb#L75
   end
 
   def test_thread_safe
+    q1 = Queue.new
     assert_raise(PStore::Error) do
-      flag = false
       th = Thread.new do
         @pstore.transaction do
           @pstore[:foo] = "bar"
-          flag = true
-          sleep 1
+          q1.push true
+          sleep
         end
       end
       begin
-        sleep 0.1 until flag
+        q1.pop
         @pstore.transaction {}
       ensure
+        th.kill
         th.join
       end
     end
+    q2 = Queue.new
     begin
       pstore = PStore.new(second_file, true)
-      flag = false
+      cur = Thread.current
       th = Thread.new do
         pstore.transaction do
           pstore[:foo] = "bar"
-          flag = true
-          sleep 1
+          q1.push true
+          q2.pop
+          # wait for cur to enter a transaction
+          sleep 0.1 until cur.stop?
         end
       end
       begin
-        sleep 0.1 until flag
+        q1.pop
+        q2.push true
         assert_equal("bar", pstore.transaction { pstore[:foo] })
       ensure
         th.join

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

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