summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-10 18:05:41 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-10 18:05:41 -0800
commit56378c0fc1704cab0e0e1e6800befaf84e419b43 (patch)
tree704cce47b2012c795f36f1a1dbf66d4517c18e03
parent93e36dd664a9d3f95456769ca2d29c48503bd0e7 (diff)
Too tricky to support, for now.
-rw-r--r--lib/tdb/mt.rb8
-rw-r--r--test/test_tdb_mt.rb23
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