Skip to content
Permalink
Browse files

guard against undefined method

  • Loading branch information
AlexanderZagaynov authored and pitr-ch committed Oct 7, 2019
1 parent ad087b7 commit e5749156de8ff328d12211c5d75efffd5d144f0d
@@ -300,7 +300,9 @@ def initialize(pool, id: nil)
@queue = Queue.new
@pool = pool
@thread = create_worker @queue, pool, pool.idletime
@thread.name = [pool.name, 'worker', id].compact.join('-')
if Concurrent.on_cruby? && Concurrent.ruby_version(:>=, 2, 3, 0)
@thread.name = [pool.name, 'worker', id].compact.join('-')
end
end

def <<(message)
@@ -55,34 +55,36 @@ module Concurrent
end
end

context 'threads naming' do
subject do
opts = { min_threads: 2 }
opts[:name] = pool_name if pool_name
described_class.new(opts)
end
if Concurrent.on_cruby? && Concurrent.ruby_version(:>=, 2, 3, 0)
context 'threads naming' do
subject do
opts = { min_threads: 2 }
opts[:name] = pool_name if pool_name
described_class.new(opts)
end

let(:names) { Concurrent::Set.new }
let(:names) { Concurrent::Set.new }

before do
subject.post(names) { |names| names << Thread.current.name }
subject.post(names) { |names| names << Thread.current.name }
subject.shutdown
subject.wait_for_termination(pool_termination_timeout)
expect(names.size).to eq 2
end
before do
subject.post(names) { |names| names << Thread.current.name }
subject.post(names) { |names| names << Thread.current.name }
subject.shutdown
subject.wait_for_termination(pool_termination_timeout)
expect(names.size).to eq 2
end

context 'without pool name' do
let(:pool_name) { }
it 'sets counted name' do
expect(names.all? { |name| name =~ /^worker-\d+$/ }).to be true
context 'without pool name' do
let(:pool_name) { }
it 'sets counted name' do
expect(names.all? { |name| name =~ /^worker-\d+$/ }).to be true
end
end
end

context 'with pool name' do
let(:pool_name) { 'MyExecutor' }
it 'sets counted name' do
expect(names.all? { |name| name =~ /^MyExecutor-worker-\d+$/ }).to be true
context 'with pool name' do
let(:pool_name) { 'MyExecutor' }
it 'sets counted name' do
expect(names.all? { |name| name =~ /^MyExecutor-worker-\d+$/ }).to be true
end
end
end
end

0 comments on commit e574915

Please sign in to comment.
You can’t perform that action at this time.