1 # -*- encoding: binary -*-
2 $stdout.sync = $stderr.sync = true
8 class Test_TDB_MT < Test::Unit::TestCase
15 return if @start_pid != $$
16 @tmp.close! if @tmp.respond_to?(:close!)
17 @tdb.close if @tdb && ! @tdb.closed?
20 def test_make_threadsafe
22 assert_kind_of TDB, @tdb
23 assert ! @tdb.threadsafe?
24 assert_nothing_raised { @tdb.threadsafe! }
25 assert @tdb.threadsafe?
28 def test_init_threadsafe
29 @tdb = TDB.new(nil, :threadsafe => true)
30 assert @tdb.threadsafe?
32 @tdb = TDB.new(nil, :threadsafe => false)
33 assert ! @tdb.threadsafe?
36 assert ! @tdb.threadsafe?
40 def test_thread_safe_torture_test
41 @tmp = Tempfile.new('tdb_test')
42 File.unlink(@tmp.path)
43 @tdb = TDB.new(@tmp.path)
44 assert_nothing_raised { @tdb.threadsafe! }
45 Thread.abort_on_exception = true
56 threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } }
57 threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } }
58 threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } }
59 threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } }
60 threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } }
64 threads.each { |t| t.join }
66 10.times { fork &crazy }
67 Process.waitall.each do |(pid,status)|
68 assert status.success?, status.inspect
70 nr.times { |i| assert_equal blob, @tdb[i.to_s] }
73 def test_check_methods
74 m = TDB.instance_methods.sort
75 m -= Object.instance_methods
76 m -= Enumerable.instance_methods
77 m.map! { |x| x.to_sym }
78 mt = TDB::MT.instance_methods.sort
80 m += [ :include?, :member? ]
82 unwrapped = ( (m - mt) | (mt - m)).uniq
83 assert unwrapped.empty?, "unwrapped methods: #{unwrapped.inspect}"
85 respond_to?(:refute_match) and
86 m.each { |meth| refute_match(/\bTDB::MT\b/, @tdb.method(meth).to_s) }
88 m.each { |meth| assert_match(/\bTDB::MT\b/, @tdb.method(meth).to_s) }