From 56378c0fc1704cab0e0e1e6800befaf84e419b43 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 10 Dec 2010 18:05:41 -0800 Subject: mt: just break when attempting TDB methods inside #each Too tricky to support, for now. --- lib/tdb/mt.rb | 8 +------- test/test_tdb_mt.rb | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/tdb/mt.rb b/lib/tdb/mt.rb index 7e7a09d..7ff2196 100644 --- a/lib/tdb/mt.rb +++ b/lib/tdb/mt.rb @@ -12,19 +12,13 @@ module TDB::MT lockall trylockall unlockall lockall_read trylockall_read unlockall_read lockall_mark lockall_unmark - clear + clear each ) wrap_methods << :repack if TDB.method_defined?(:repack) wrap_methods.each do |meth| eval "def #{meth}(*args); @lock.synchronize { super }; end" end - def each(&block) - @lock.synchronize do - super { |k,v| @lock.exclusive_unlock { yield(k,v) } } - end - end - def threadsafe? true end diff --git a/test/test_tdb_mt.rb b/test/test_tdb_mt.rb index 0fbe09f..0e3517c 100644 --- a/test/test_tdb_mt.rb +++ b/test/test_tdb_mt.rb @@ -23,7 +23,6 @@ class Test_TDB_MT < Test::Unit::TestCase assert ! @tdb.threadsafe? assert_nothing_raised { @tdb.threadsafe! } assert @tdb.threadsafe? - @tdb.each { |k,v| assert_equal v, @tdb[k] } end def test_init_threadsafe @@ -39,13 +38,15 @@ class Test_TDB_MT < Test::Unit::TestCase end def test_thread_safe_torture_test - @tdb = TDB.new(nil) + @tmp = Tempfile.new('tdb_test') + File.unlink(@tmp.path) + @tdb = TDB.new(@tmp.path) assert_nothing_raised { @tdb.threadsafe! } - pid = fork do - Thread.abort_on_exception = true + Thread.abort_on_exception = true + nr = 1000 + blob = 'foo' * 1000 + crazy = proc do threads = [] - blob = 'foo' * 1000 - nr = 10000 t = Thread.new do while true Thread.pass @@ -56,13 +57,17 @@ class Test_TDB_MT < Test::Unit::TestCase threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } } threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } } threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } } + threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } } threads << t - + sleep 1 t.kill threads.each { |t| t.join } end - _, status = Process.waitpid2(pid) - assert status.success?, status.inspect + 10.times { fork &crazy } + Process.waitall.each do |(pid,status)| + assert status.success?, status.inspect + end + nr.times { |i| assert_equal blob, @tdb[i.to_s] } end def test_check_methods -- cgit v1.2.3-24-ge0c7