diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-28 14:12:33 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-28 14:12:33 +0000 |
commit | 2e58d3fd63384fe1f5a0c2da1bd269986d40e31d (patch) | |
tree | 7c080dfab012c9ee93d702dba0596e17ddb74748 /test | |
parent | 13fdfb89aa0745bb204f7e2c81fee90949342c1c (diff) | |
download | ruby-2e58d3fd63384fe1f5a0c2da1bd269986d40e31d.tar.gz |
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
Diffstat (limited to 'test')
-rw-r--r-- | test/test_pstore.rb | 21 |
1 files changed, 13 insertions, 8 deletions
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 |