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
@ -75,34 +75,39 @@ class PStoreTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_thread_safe
|
def test_thread_safe
|
||||||
|
q1 = Queue.new
|
||||||
assert_raise(PStore::Error) do
|
assert_raise(PStore::Error) do
|
||||||
flag = false
|
|
||||||
th = Thread.new do
|
th = Thread.new do
|
||||||
@pstore.transaction do
|
@pstore.transaction do
|
||||||
@pstore[:foo] = "bar"
|
@pstore[:foo] = "bar"
|
||||||
flag = true
|
q1.push true
|
||||||
sleep 1
|
sleep
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
sleep 0.1 until flag
|
q1.pop
|
||||||
@pstore.transaction {}
|
@pstore.transaction {}
|
||||||
ensure
|
ensure
|
||||||
|
th.kill
|
||||||
th.join
|
th.join
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
q2 = Queue.new
|
||||||
begin
|
begin
|
||||||
pstore = PStore.new(second_file, true)
|
pstore = PStore.new(second_file, true)
|
||||||
flag = false
|
cur = Thread.current
|
||||||
th = Thread.new do
|
th = Thread.new do
|
||||||
pstore.transaction do
|
pstore.transaction do
|
||||||
pstore[:foo] = "bar"
|
pstore[:foo] = "bar"
|
||||||
flag = true
|
q1.push true
|
||||||
sleep 1
|
q2.pop
|
||||||
|
# wait for cur to enter a transaction
|
||||||
|
sleep 0.1 until cur.stop?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
sleep 0.1 until flag
|
q1.pop
|
||||||
|
q2.push true
|
||||||
assert_equal("bar", pstore.transaction { pstore[:foo] })
|
assert_equal("bar", pstore.transaction { pstore[:foo] })
|
||||||
ensure
|
ensure
|
||||||
th.join
|
th.join
|
||||||
|
Loading…
x
Reference in New Issue
Block a user