Skip to content

Commit

Permalink
Align Java Executor Service behavior for shuttingdown?, shutdown?
Browse files Browse the repository at this point in the history
Co-authored-by: Benoit Daloze <[email protected]>
  • Loading branch information
bensheldon and eregon committed Mar 11, 2024
1 parent 899621f commit 8b9b0da
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@ def ns_running?
end

def ns_shuttingdown?
if @executor.respond_to? :isTerminating
@executor.isTerminating
else
false
end
@executor.isShutdown && !@executor.isTerminated
end

def ns_shutdown?
@executor.isShutdown || @executor.isTerminated
@executor.isTerminated
end

class Job
Expand Down
44 changes: 43 additions & 1 deletion spec/concurrent/executor/executor_service_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'concurrent/atomic/atomic_fixnum'
require 'timeout'

RSpec.shared_examples :executor_service do
RSpec.shared_examples :executor_service do |immediate_type: false|

after(:each) do
subject.shutdown
Expand Down Expand Up @@ -84,6 +84,48 @@
end
end

context '#shuttingdown?' do
it 'returns false when the thread pool is running' do
expect(subject).not_to be_shuttingdown
end

it 'returns true when the thread pool is shutting down' do
skip "will never be in shuttingdown? state" if immediate_type

subject.post{ sleep(0.5) }
subject.shutdown
expect(subject).to be_shuttingdown
expect(subject.wait_for_termination(pool_termination_timeout)).to eq true
end

it 'returns false when the thread pool is shutdown' do
subject.shutdown
expect(subject.wait_for_termination(pool_termination_timeout)).to eq true
expect(subject).not_to be_shuttingdown
end
end

context '#shutdown?' do
it 'returns false when the thread pool is running' do
expect(subject).not_to be_shutdown
end

it 'returns false when the thread pool is shutting down' do
skip "will never be in shuttingdown? state" if immediate_type

subject.post{ sleep(0.5) }
subject.shutdown
expect(subject).not_to be_shutdown
expect(subject.wait_for_termination(pool_termination_timeout)).to eq true
end

it 'returns true when the thread pool is shutdown' do
subject.shutdown
expect(subject.wait_for_termination(pool_termination_timeout)).to eq true
expect(subject).to be_shutdown
end
end

context '#shutdown' do

it 'stops accepting new tasks' do
Expand Down
2 changes: 1 addition & 1 deletion spec/concurrent/executor/immediate_executor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module Concurrent

subject { ImmediateExecutor.new }

it_should_behave_like :executor_service
it_should_behave_like :executor_service, immediate_type: true
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Concurrent

subject { IndirectImmediateExecutor.new }

it_should_behave_like :executor_service
it_should_behave_like :executor_service, immediate_type: true

it "runs its tasks synchronously" do
start = Time.now
Expand Down
2 changes: 1 addition & 1 deletion spec/concurrent/executor/serialized_execution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ module Concurrent

subject { SerializedExecutionDelegator.new(ImmediateExecutor.new) }

it_should_behave_like :executor_service
it_should_behave_like :executor_service, immediate_type: true
end
end

0 comments on commit 8b9b0da

Please sign in to comment.