From e267617f3e359cf40a28ba3baa360b9cd7ca2bf2 Mon Sep 17 00:00:00 2001 From: sorah Date: Mon, 7 Mar 2011 14:03:41 +0000 Subject: * lib/pstore.rb: Delete variable @transaction and fix #4474. Patch by Masaki Matsushita (Glass_saga). * test/test_pstore.rb(test_thread_safe): Add test for #4474. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/test_pstore.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/test_pstore.rb') diff --git a/test/test_pstore.rb b/test/test_pstore.rb index e10ce906cb..32d79ea2ba 100644 --- a/test/test_pstore.rb +++ b/test/test_pstore.rb @@ -71,4 +71,33 @@ class PStoreTest < Test::Unit::TestCase end end end + + def test_thread_safe + assert_raise(PStore::Error) do + flag = false + Thread.new do + @pstore.transaction do + @pstore[:foo] = "bar" + flag = true + sleep 1 + end + end + until flag; end + @pstore.transaction {} + end + assert_block do + pstore = PStore.new("pstore.tmp2.#{Process.pid}",true) + flag = false + Thread.new do + pstore.transaction do + pstore[:foo] = "bar" + flag = true + sleep 1 + end + end + until flag; end + pstore.transaction { pstore[:foo] == "bar" } + File.unlink("pstore.tmp2.#{Process.pid}") rescue nil + end + end end -- cgit v1.2.1