Skip to content

Commit 8b9b0da

Browse files
bensheldoneregon
andcommitted
Align Java Executor Service behavior for shuttingdown?, shutdown?
Co-authored-by: Benoit Daloze <[email protected]>
1 parent 899621f commit 8b9b0da

File tree

5 files changed

+48
-10
lines changed

5 files changed

+48
-10
lines changed

lib/concurrent-ruby/concurrent/executor/java_executor_service.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,11 @@ def ns_running?
5757
end
5858

5959
def ns_shuttingdown?
60-
if @executor.respond_to? :isTerminating
61-
@executor.isTerminating
62-
else
63-
false
64-
end
60+
@executor.isShutdown && !@executor.isTerminated
6561
end
6662

6763
def ns_shutdown?
68-
@executor.isShutdown || @executor.isTerminated
64+
@executor.isTerminated
6965
end
7066

7167
class Job

spec/concurrent/executor/executor_service_shared.rb

+43-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'concurrent/atomic/atomic_fixnum'
44
require 'timeout'
55

6-
RSpec.shared_examples :executor_service do
6+
RSpec.shared_examples :executor_service do |immediate_type: false|
77

88
after(:each) do
99
subject.shutdown
@@ -84,6 +84,48 @@
8484
end
8585
end
8686

87+
context '#shuttingdown?' do
88+
it 'returns false when the thread pool is running' do
89+
expect(subject).not_to be_shuttingdown
90+
end
91+
92+
it 'returns true when the thread pool is shutting down' do
93+
skip "will never be in shuttingdown? state" if immediate_type
94+
95+
subject.post{ sleep(0.5) }
96+
subject.shutdown
97+
expect(subject).to be_shuttingdown
98+
expect(subject.wait_for_termination(pool_termination_timeout)).to eq true
99+
end
100+
101+
it 'returns false when the thread pool is shutdown' do
102+
subject.shutdown
103+
expect(subject.wait_for_termination(pool_termination_timeout)).to eq true
104+
expect(subject).not_to be_shuttingdown
105+
end
106+
end
107+
108+
context '#shutdown?' do
109+
it 'returns false when the thread pool is running' do
110+
expect(subject).not_to be_shutdown
111+
end
112+
113+
it 'returns false when the thread pool is shutting down' do
114+
skip "will never be in shuttingdown? state" if immediate_type
115+
116+
subject.post{ sleep(0.5) }
117+
subject.shutdown
118+
expect(subject).not_to be_shutdown
119+
expect(subject.wait_for_termination(pool_termination_timeout)).to eq true
120+
end
121+
122+
it 'returns true when the thread pool is shutdown' do
123+
subject.shutdown
124+
expect(subject.wait_for_termination(pool_termination_timeout)).to eq true
125+
expect(subject).to be_shutdown
126+
end
127+
end
128+
87129
context '#shutdown' do
88130

89131
it 'stops accepting new tasks' do

spec/concurrent/executor/immediate_executor_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ module Concurrent
77

88
subject { ImmediateExecutor.new }
99

10-
it_should_behave_like :executor_service
10+
it_should_behave_like :executor_service, immediate_type: true
1111
end
1212
end

spec/concurrent/executor/indirect_immediate_executor_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Concurrent
77

88
subject { IndirectImmediateExecutor.new }
99

10-
it_should_behave_like :executor_service
10+
it_should_behave_like :executor_service, immediate_type: true
1111

1212
it "runs its tasks synchronously" do
1313
start = Time.now

spec/concurrent/executor/serialized_execution_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ module Concurrent
88

99
subject { SerializedExecutionDelegator.new(ImmediateExecutor.new) }
1010

11-
it_should_behave_like :executor_service
11+
it_should_behave_like :executor_service, immediate_type: true
1212
end
1313
end

0 commit comments

Comments
 (0)