git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-05-31 00:01:32 +00:00
Родитель dd20f90408
Коммит 1c01f22d93
1 изменённых файлов: 14 добавлений и 6 удалений

Просмотреть файл

@ -77,28 +77,36 @@ class PStoreTest < Test::Unit::TestCase
def test_thread_safe def test_thread_safe
assert_raise(PStore::Error) do assert_raise(PStore::Error) do
flag = false flag = false
Thread.new do th = Thread.new do
@pstore.transaction do @pstore.transaction do
@pstore[:foo] = "bar" @pstore[:foo] = "bar"
flag = true flag = true
sleep 1 sleep 1
end end
end end
sleep 0.1 until flag begin
@pstore.transaction {} sleep 0.1 until flag
@pstore.transaction {}
ensure
th.join
end
end end
begin begin
pstore = PStore.new(second_file, true) pstore = PStore.new(second_file, true)
flag = false flag = false
Thread.new do th = Thread.new do
pstore.transaction do pstore.transaction do
pstore[:foo] = "bar" pstore[:foo] = "bar"
flag = true flag = true
sleep 1 sleep 1
end end
end end
sleep 0.1 until flag begin
assert_equal("bar", pstore.transaction { pstore[:foo] }) sleep 0.1 until flag
assert_equal("bar", pstore.transaction { pstore[:foo] })
ensure
th.join
end
end end
ensure ensure
File.unlink(second_file) rescue nil File.unlink(second_file) rescue nil