about summary refs log tree commit homepage
path: root/test
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 /test
parent93e36dd664a9d3f95456769ca2d29c48503bd0e7 (diff)
downloadruby-tdb-56378c0fc1704cab0e0e1e6800befaf84e419b43.tar.gz
Too tricky to support, for now.
Diffstat (limited to 'test')
-rw-r--r--test/test_tdb_mt.rb23
1 files changed, 14 insertions, 9 deletions
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