mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
0b149ab5f3
commit
d90b767d2b
1 changed files with 13 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue