Skip to content

Commit e574915

Browse files
AlexanderZagaynovpitr-ch
authored andcommitted
guard against undefined method
1 parent ad087b7 commit e574915

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

lib/concurrent/executor/ruby_thread_pool_executor.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ def initialize(pool, id: nil)
300300
@queue = Queue.new
301301
@pool = pool
302302
@thread = create_worker @queue, pool, pool.idletime
303-
@thread.name = [pool.name, 'worker', id].compact.join('-')
303+
if Concurrent.on_cruby? && Concurrent.ruby_version(:>=, 2, 3, 0)
304+
@thread.name = [pool.name, 'worker', id].compact.join('-')
305+
end
304306
end
305307

306308
def <<(message)

spec/concurrent/executor/ruby_thread_pool_executor_spec.rb

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,34 +55,36 @@ module Concurrent
5555
end
5656
end
5757

58-
context 'threads naming' do
59-
subject do
60-
opts = { min_threads: 2 }
61-
opts[:name] = pool_name if pool_name
62-
described_class.new(opts)
63-
end
58+
if Concurrent.on_cruby? && Concurrent.ruby_version(:>=, 2, 3, 0)
59+
context 'threads naming' do
60+
subject do
61+
opts = { min_threads: 2 }
62+
opts[:name] = pool_name if pool_name
63+
described_class.new(opts)
64+
end
6465

65-
let(:names) { Concurrent::Set.new }
66+
let(:names) { Concurrent::Set.new }
6667

67-
before do
68-
subject.post(names) { |names| names << Thread.current.name }
69-
subject.post(names) { |names| names << Thread.current.name }
70-
subject.shutdown
71-
subject.wait_for_termination(pool_termination_timeout)
72-
expect(names.size).to eq 2
73-
end
68+
before do
69+
subject.post(names) { |names| names << Thread.current.name }
70+
subject.post(names) { |names| names << Thread.current.name }
71+
subject.shutdown
72+
subject.wait_for_termination(pool_termination_timeout)
73+
expect(names.size).to eq 2
74+
end
7475

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

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

0 commit comments

Comments
 (0)