Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.

Commit cf1dc73

Browse files
committed
tests: remove assert_nothing_raised
Minitest doesn't support assert_nothing_raised. Remove our uses of assert_nothing_raised by either simply removing the call, or adding other basic asserts.
1 parent 3ed52e0 commit cf1dc73

File tree

5 files changed

+41
-61
lines changed

5 files changed

+41
-61
lines changed

test/test_array.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
class TestArray < Minitest::Test
55
def test_concurrency
66
ary = ThreadSafe::Array.new
7-
assert_nothing_raised do
8-
(1..100).map do |i|
9-
Thread.new do
10-
1000.times do
11-
ary << i
12-
ary.each {|x| x * 2}
13-
ary.shift
14-
ary.last
15-
end
7+
(1..100).map do |i|
8+
Thread.new do
9+
1000.times do
10+
ary << i
11+
ary.each {|x| x * 2}
12+
ary.shift
13+
ary.last
1614
end
17-
end.map(&:join)
18-
end
15+
end
16+
end.map(&:join)
1917
end
2018
end

test/test_cache.rb

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@ def setup
1111

1212
def test_concurrency
1313
cache = @cache
14-
assert_nothing_raised do
15-
(1..100).map do |i|
16-
Thread.new do
17-
1000.times do |j|
18-
key = i*1000+j
19-
cache[key] = i
20-
cache[key]
21-
cache.delete(key)
22-
end
14+
(1..100).map do |i|
15+
Thread.new do
16+
1000.times do |j|
17+
key = i*1000+j
18+
cache[key] = i
19+
cache[key]
20+
cache.delete(key)
2321
end
24-
end.map(&:join)
25-
end
22+
end
23+
end.map(&:join)
2624
end
2725

2826
def test_retrieval
@@ -553,11 +551,9 @@ def test_each_pair_allows_modification
553551
@cache[:b] = 1
554552
@cache[:c] = 1
555553

556-
assert_nothing_raised do
557-
assert_size_change 1 do
558-
@cache.each_pair do |k, v|
559-
@cache[:z] = 1
560-
end
554+
assert_size_change 1 do
555+
@cache.each_pair do |k, v|
556+
@cache[:z] = 1
561557
end
562558
end
563559
end
@@ -707,10 +703,9 @@ def test_is_unfreezable
707703
end
708704

709705
def test_marshal_dump_load
710-
assert_nothing_raised do
711-
new_cache = Marshal.load(Marshal.dump(@cache))
712-
assert_equal 0, new_cache.size
713-
end
706+
new_cache = Marshal.load(Marshal.dump(@cache))
707+
assert_instance_of ThreadSafe::Cache, new_cache
708+
assert_equal 0, new_cache.size
714709
@cache[:a] = 1
715710
new_cache = Marshal.load(Marshal.dump(@cache))
716711
assert_equal 1, @cache[:a]
@@ -739,7 +734,8 @@ def assert_valid_option(option_name, value)
739734
end
740735

741736
def assert_valid_options(options)
742-
assert_nothing_raised { ThreadSafe::Cache.new(options) }
737+
c = ThreadSafe::Cache.new(options)
738+
assert_instance_of ThreadSafe::Cache, c
743739
end
744740

745741
def assert_invalid_option(option_name, value)

test/test_cache_loops.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,13 @@ def add_remove_to_zero_via_merge_pair(opts = {})
309309
def do_thread_loop(name, code, options = {}, &block)
310310
options = DEFAULTS.merge(options)
311311
meth = define_loop name, code, options[:prelude]
312-
assert_nothing_raised do
313-
keys = to_keys_array(options[:key_count])
314-
run_thread_loop(meth, keys, options, &block)
315-
316-
if options[:key_count] > 1
317-
options[:key_count] = (options[:key_count] / 40).to_i
318-
keys = to_hash_collision_keys_array(options[:key_count])
319-
run_thread_loop(meth, keys, options.merge(:loop_count => (options[:loop_count] * 5)), &block)
320-
end
312+
keys = to_keys_array(options[:key_count])
313+
run_thread_loop(meth, keys, options, &block)
314+
315+
if options[:key_count] > 1
316+
options[:key_count] = (options[:key_count] / 40).to_i
317+
keys = to_hash_collision_keys_array(options[:key_count])
318+
run_thread_loop(meth, keys, options.merge(:loop_count => (options[:loop_count] * 5)), &block)
321319
end
322320
end
323321

test/test_hash.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
class TestHash < Minitest::Test
55
def test_concurrency
66
hsh = ThreadSafe::Hash.new
7-
assert_nothing_raised do
8-
(1..100).map do |i|
9-
Thread.new do
10-
1000.times do |j|
11-
hsh[i*1000+j] = i
12-
hsh[i*1000+j]
13-
hsh.delete(i*1000+j)
14-
end
7+
(1..100).map do |i|
8+
Thread.new do
9+
1000.times do |j|
10+
hsh[i*1000+j] = i
11+
hsh[i*1000+j]
12+
hsh.delete(i*1000+j)
1513
end
16-
end.map(&:join)
17-
end
14+
end
15+
end.map(&:join)
1816
end
1917
end

test/test_helper.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
Minitest::Test = MiniTest::Unit::TestCase
99
end
1010

11-
# Minitest does not support assert_nothing_raised.
12-
# Eventually we should remove our use of this assert_nothing_raised function
13-
# for more specific asserts. In the mean time, add a backwards-compatible
14-
# implementation of assert_nothing_raised.
15-
class MiniTest::Test
16-
def assert_nothing_raised(&block)
17-
block.call
18-
end
19-
end
20-
2111
if defined?(JRUBY_VERSION) && ENV['TEST_NO_UNSAFE']
2212
# to be used like this: rake test TEST_NO_UNSAFE=true
2313
load 'test/package.jar'

0 commit comments

Comments
 (0)