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
42 @tmp = Tempfile.new('tdb_test')
43 File.unlink(@tmp.path)
44 @tdb = TDB.new(@tmp.path)
45 assert_nothing_raised { @tdb.threadsafe! }
46 Thread.abort_on_exception = true
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 } }
61 threads << Thread.new { nr.times { |i| @tdb[i.to_s] = blob } }
65 threads.each { |t| t.join }
67 10.times { fork &crazy }
68 Process.waitall.each do |(pid,status)|
69 assert status.success?, status.inspect
71 nr.times { |i| assert_equal blob, @tdb[i.to_s] }
74 def test_check_methods
75 m = TDB.instance_methods.sort
77 warn "skipping test under Ruby 1.8"
80 m -= Object.instance_methods
81 m -= Enumerable.instance_methods
82 m.map! { |x| x.to_sym }
83 mt = TDB::MT.instance_methods.sort
85 m += [ :include?, :member? ]
87 unwrapped = ( (m - mt) | (mt - m)).uniq
88 unwrapped -= [ :initialize ]
89 assert unwrapped.empty?, "unwrapped methods: #{unwrapped.inspect}"
91 respond_to?(:refute_match) and
92 m.each { |meth| refute_match(/\bTDB::MT\b/, @tdb.method(meth).to_s) }
93 before = m.map { |meth| [ meth, @tdb.method(meth).to_s ] }
95 before.each do |(meth, old)|
96 refute_equal old, @tdb.method(meth).to_s