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. --- test/test_tdb_mt.rb | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'test') 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