Skip to content

Commit e14ccb3

Browse files
committed
Reduce output pollution by warnings
1 parent a6fc08f commit e14ccb3

File tree

7 files changed

+17
-14
lines changed

7 files changed

+17
-14
lines changed

lib/concurrent/async.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def await
435435
#
436436
# @!visibility private
437437
def init_synchronization
438-
return self if @__async_initialized__
438+
return self if defined?(@__async_initialized__) && @__async_initialized__
439439
@__async_initialized__ = true
440440
@__async_delegator__ = AsyncDelegator.new(self)
441441
@__await_delegator__ = AwaitDelegator.new(@__async_delegator__)

lib/concurrent/mutable_struct.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def define_struct(name, members, &block)
212212
synchronize do
213213
clazz = Synchronization::AbstractStruct.define_struct_class(MutableStruct, Synchronization::LockableObject, name, members, &block)
214214
members.each_with_index do |member, index|
215+
clazz.send :remove_method, member
215216
clazz.send(:define_method, member) do
216217
synchronize { @values[index] }
217218
end

lib/concurrent/settable_struct.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def define_struct(name, members, &block)
107107
synchronize do
108108
clazz = Synchronization::AbstractStruct.define_struct_class(SettableStruct, Synchronization::LockableObject, name, members, &block)
109109
members.each_with_index do |member, index|
110+
clazz.send :remove_method, member if clazz.instance_methods.include? member
110111
clazz.send(:define_method, member) do
111112
synchronize { @values[index] }
112113
end

lib/concurrent/synchronization/abstract_struct.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def ns_initialize(*values)
146146
end
147147
end
148148
members.each_with_index do |member, index|
149-
clazz.send :remove_method, member if clazz.method_defined? member
149+
clazz.send :remove_method, member if clazz.instance_methods.include? member
150150
clazz.send(:define_method, member) do
151151
@values[index]
152152
end

lib/concurrent/timer_task.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ def ns_initialize(opts, &task)
281281
@run_now = opts[:now] || opts[:run_now]
282282
@executor = Concurrent::SafeTaskExecutor.new(task)
283283
@running = Concurrent::AtomicBoolean.new(false)
284+
@value = nil
284285

285286
self.observers = Collection::CopyOnNotifyObserverSet.new
286287
end

spec/concurrent/concern/obligation_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ module Concern
44
RSpec.describe Obligation do
55

66
let (:obligation_class) do
7-
87
Class.new(Synchronization::LockableObject) do
98
include Obligation
109
public :state=, :compare_and_set_state, :if_state
1110
attr_writer :value, :reason
12-
def ns_initialize
11+
def initialize
12+
super
13+
set_deref_options
1314
init_obligation
1415
end
1516
end
@@ -72,8 +73,7 @@ def ns_initialize
7273
context 'fulfilled' do
7374

7475
before(:each) do
75-
obligation.state = :fulfilled
76-
obligation.send(:value=, 42)
76+
obligation.send :set_state, true, 42, nil
7777
allow(obligation).to receive(:event).and_return(event)
7878
end
7979

@@ -150,7 +150,7 @@ def ns_initialize
150150
context 'rejected' do
151151

152152
before(:each) do
153-
obligation.state = :rejected
153+
obligation.send :set_state, false, nil, (raise rescue $!)
154154
allow(obligation).to receive(:event).and_return(event)
155155
end
156156

@@ -190,19 +190,19 @@ def ns_initialize
190190
it 'should return immediately if timeout is zero' do
191191
expect(event).not_to receive(:wait)
192192

193-
expect { obligation.value!(0) }.to raise_error
193+
expect { obligation.value!(0) }.to raise_error StandardError
194194
end
195195

196196
it 'should return immediately if timeout is not set' do
197197
expect(event).not_to receive(:wait)
198198

199-
expect { obligation.value! }.to raise_error
199+
expect { obligation.value! }.to raise_error StandardError
200200
end
201201

202202
it 'should return immediately if timeout is not zero' do
203203
expect(event).not_to receive(:wait)
204204

205-
expect { obligation.value!(5) }.to raise_error
205+
expect { obligation.value!(5) }.to raise_error StandardError
206206
end
207207

208208
end
@@ -212,19 +212,19 @@ def ns_initialize
212212
it 'should return immediately if timeout is zero' do
213213
expect(event).not_to receive(:wait)
214214

215-
expect { obligation.no_error!(0) }.to raise_error
215+
expect { obligation.no_error!(0) }.to raise_error StandardError
216216
end
217217

218218
it 'should return immediately if timeout is not set' do
219219
expect(event).not_to receive(:wait)
220220

221-
expect { obligation.no_error! }.to raise_error
221+
expect { obligation.no_error! }.to raise_error StandardError
222222
end
223223

224224
it 'should return immediately if timeout is not zero' do
225225
expect(event).not_to receive(:wait)
226226

227-
expect { obligation.no_error!(5) }.to raise_error
227+
expect { obligation.no_error!(5) }.to raise_error StandardError
228228
end
229229

230230
end

spec/concurrent/timer_task_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Concurrent
88
context :dereferenceable do
99

1010
def kill_subject
11-
@subject.kill if @subject
11+
@subject.kill if defined?(@subject) && @subject
1212
rescue Exception => ex
1313
# prevent exceptions with mocks in tests
1414
end

0 commit comments

Comments
 (0)