Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align Java Executor Service behavior for shuttingdown?, shutdown? #1042

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 && [email protected]
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