Skip to content

Commit d82334d

Browse files
committed
Attempt to improve Dereferenceable shared specs.
1 parent 73496e7 commit d82334d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

spec/concurrent/dereferenceable_shared.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,27 @@
119119

120120
if dereferenceable_subject(0).respond_to?(:add_observer)
121121

122+
latch = Concurrent::CountDownLatch.new
123+
observer = Class.new do
124+
def initialize(latch)
125+
@latch = latch
126+
end
127+
def update(*args)
128+
@latch.count_down
129+
end
130+
end.new(latch)
131+
122132
result = 'result'
133+
copier = proc { result }
123134
expect(result).to receive(:dup).at_least(:once).and_return(result)
124135
expect(result).to receive(:freeze).at_least(:once).and_return(result)
125-
copier = proc { result }
126-
127-
observer = double('observer')
128-
expect(observer).to receive(:update).at_least(:once).with(any_args)
136+
expect(copier).to receive(:call).at_least(:once).and_return(result)
129137

130138
subject = dereferenceable_observable(dup_on_deref: true, freeze_on_deref: true, copy_on_deref: copier)
131139

132140
subject.add_observer(observer)
133141
execute_dereferenceable(subject)
142+
latch.wait(1)
134143
end
135144
end
136145
end

0 commit comments

Comments
 (0)