From 2e58d3fd63384fe1f5a0c2da1bd269986d40e31d Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 28 Sep 2016 14:12:33 +0000 Subject: test_pstore.rb: use queues * test/test_pstore.rb (PStoreTest#test_thread_safe): handshake by queues, and reduce sleeping time. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/test_pstore.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'test/test_pstore.rb') diff --git a/test/test_pstore.rb b/test/test_pstore.rb index e7fe4f1d15..e584e2f045 100644 --- a/test/test_pstore.rb +++ b/test/test_pstore.rb @@ -75,34 +75,39 @@ class PStoreTest < Test::Unit::TestCase 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 -- cgit v1.2.3