summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-28 14:12:33 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-28 14:12:33 +0000
commitd90b767d2bf346c87132e62df9c2159f7c8b97c0 (patch)
tree7c080dfab012c9ee93d702dba0596e17ddb74748 /test
parent0b149ab5f350aea7b803f67c87f35e68d3bf8556 (diff)
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.rb21
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