Skip to content

Commit 7921b49

Browse files
committed
Fixed buggy test setup and remove kill_rogue_threads.
1 parent 2be2f43 commit 7921b49

File tree

4 files changed

+17
-44
lines changed

4 files changed

+17
-44
lines changed

spec/concurrent/actor_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ module Actor
1515
# end
1616

1717
describe 'Concurrent::Actor' do
18-
prepend_before do
19-
do_no_reset!
20-
end
2118

2219
def terminate_actors(*actors)
2320
actors.each do |actor|

spec/concurrent/configuration_spec.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ module Concurrent
33
describe Configuration do
44

55
before(:each) do
6-
reset_gem_configuration
7-
end
8-
9-
after(:each) do
6+
# redundant - done in spec_helper.rb
7+
# done here again for explicitness
108
reset_gem_configuration
119
end
1210

@@ -28,9 +26,9 @@ module Concurrent
2826
end
2927

3028
specify '#terminate_pools! acts on all executors with auto_terminate: true' do
31-
expect(Concurrent.global_fast_executor).to receive(:kill).with(no_args).and_call_original
32-
expect(Concurrent.global_io_executor).to receive(:kill).with(no_args).and_call_original
33-
expect(Concurrent.global_timer_set).to receive(:kill).with(no_args).and_call_original
29+
expect(Concurrent.global_fast_executor).to receive(:kill).once.with(no_args).and_call_original
30+
expect(Concurrent.global_io_executor).to receive(:kill).once.with(no_args).and_call_original
31+
expect(Concurrent.global_timer_set).to receive(:kill).once.with(no_args).and_call_original
3432
Concurrent.terminate_pools!
3533
end
3634
end

spec/spec_helper.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
require 'coveralls'
33

44
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5-
SimpleCov::Formatter::HTMLFormatter,
6-
Coveralls::SimpleCov::Formatter
5+
SimpleCov::Formatter::HTMLFormatter,
6+
Coveralls::SimpleCov::Formatter
77
]
88

99
SimpleCov.start do
@@ -40,9 +40,4 @@
4040
#TODO: Better configuration management in individual test suites
4141
reset_gem_configuration
4242
end
43-
44-
config.after(:each) do
45-
#TODO: Better thread management in individual test suites
46-
kill_rogue_threads(false)
47-
end
4843
end

spec/support/example_group_extensions.rb

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,23 @@ def delta(v1, v2)
1616
include EngineDetector
1717

1818
def use_c_extensions?
19-
Concurrent.allow_c_extensions? # from extension_helper.rb
20-
end
21-
22-
def do_no_reset!
23-
@do_not_reset = true
19+
Concurrent.allow_c_extensions?
2420
end
2521

2622
GLOBAL_EXECUTORS = [
27-
[:GLOBAL_FAST_EXECUTOR, -> { Delay.new { Concurrent.new_fast_executor(auto_terminate: true) } }],
28-
[:GLOBAL_IO_EXECUTOR, -> { Delay.new { Concurrent.new_io_executor(auto_terminate: true) } }],
29-
[:GLOBAL_TIMER_SET, -> { Delay.new { Concurrent::TimerSet.new(auto_terminate: true) } }],
23+
[:GLOBAL_FAST_EXECUTOR, -> { Delay.new { Concurrent.new_fast_executor(auto_terminate: true) } }],
24+
[:GLOBAL_IO_EXECUTOR, -> { Delay.new { Concurrent.new_io_executor(auto_terminate: true) } }],
25+
[:GLOBAL_TIMER_SET, -> { Delay.new { Concurrent::TimerSet.new(auto_terminate: true) } }],
3026
]
3127

32-
@@killed = false
33-
3428
def reset_gem_configuration
35-
if @@killed
36-
GLOBAL_EXECUTORS.each do |var, factory|
37-
executor = Concurrent.const_get(var).value!
38-
executor.shutdown
39-
executor.kill
40-
Concurrent.const_set(var, factory.call)
41-
end
42-
@@killed = false
43-
end
44-
end
45-
46-
def kill_rogue_threads(warning = true)
47-
return if @do_not_reset
48-
warn('[DEPRECATED] brute force thread control being used -- tests need updated') if warning
49-
Thread.list.each do |thread|
50-
thread.kill unless thread == Thread.current
29+
GLOBAL_EXECUTORS.each do |var, factory|
30+
executor = Concurrent.const_get(var).value!
31+
executor.shutdown
32+
executor.wait_for_termination(0.2)
33+
executor.kill
34+
Concurrent.const_set(var, factory.call)
5135
end
52-
@@killed = true
5336
end
5437

5538
def monotonic_interval

0 commit comments

Comments
 (0)