Skip to content

Commit 24b55fc

Browse files
committed
Merge pull request #309 from ruby-concurrency/fixes-ruby-head-synchronization-failures
Fixes TimerSet and ScheduledTask failures on ruby-head.
2 parents 90117ff + 190b8f7 commit 24b55fc

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

lib/concurrent/scheduled_task.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def schedule_time
208208
#
209209
# @!visibility private
210210
def <=>(other)
211-
self.schedule_time <=> other.schedule_time
211+
schedule_time <=> other.schedule_time
212212
end
213213

214214
# Has the task been cancelled?

spec/concurrent/executor/timer_set_spec.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,11 @@ module Concurrent
235235
let(:queue) { subject.instance_variable_get(:@queue) }
236236

237237
it 'raises an exception when given an invalid time' do
238-
expect(queue).to receive(:push).once.with(any_args).and_call_original
239238
task = subject.post(10){ nil }
240239
expect{ task.reschedule(-1) }.to raise_error(ArgumentError)
241240
end
242241

243242
it 'does not change the current schedule when given an invalid time' do
244-
expect(queue).to receive(:push).once.with(any_args).and_call_original
245243
task = subject.post(10){ nil }
246244
expected = task.schedule_time
247245
begin
@@ -254,7 +252,6 @@ module Concurrent
254252
it 'reschdules a pending and unpost task when given a valid time' do
255253
initial_delay = 10
256254
rescheduled_delay = 20
257-
expect(queue).to receive(:push).twice.with(any_args).and_call_original
258255
task = subject.post(initial_delay){ nil }
259256
original_schedule = task.schedule_time
260257
success = task.reschedule(rescheduled_delay)
@@ -264,7 +261,6 @@ module Concurrent
264261
end
265262

266263
it 'returns false once the task has been post to the executor' do
267-
expect(queue).to receive(:push).once.with(any_args).and_call_original
268264
start_latch = Concurrent::CountDownLatch.new
269265
continue_latch = Concurrent::CountDownLatch.new
270266

@@ -282,7 +278,6 @@ module Concurrent
282278
end
283279

284280
it 'returns false once the task is processing' do
285-
expect(queue).to receive(:push).once.with(any_args).and_call_original
286281
start_latch = Concurrent::CountDownLatch.new
287282
continue_latch = Concurrent::CountDownLatch.new
288283
task = subject.post(0.1) do
@@ -299,7 +294,6 @@ module Concurrent
299294
end
300295

301296
it 'returns false once the task has is complete' do
302-
expect(queue).to receive(:push).once.with(any_args).and_call_original
303297
task = subject.post(0.1){ nil }
304298
task.value(2)
305299
expected = task.schedule_time
@@ -309,7 +303,6 @@ module Concurrent
309303
end
310304

311305
it 'returns false when not running' do
312-
expect(queue).to receive(:push).once.with(any_args).and_call_original
313306
task = subject.post(10){ nil }
314307
subject.shutdown
315308
subject.wait_for_termination(2)

spec/concurrent/scheduled_task_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ def trigger_observable(observable)
175175

176176
it 'uses the :timer_set from the options' do
177177
timer = Concurrent::TimerSet.new
178-
expect(timer).to receive(:post_task).once.with(any_args).and_return(false)
178+
queue = timer.instance_variable_get(:@queue)
179179
task = ScheduledTask.execute(1, timer_set: timer){ nil }
180+
expect(queue.size).to eq 1
181+
task.cancel
180182
end
181183

182184
it 'sets the state to :processing when the task is running' do

0 commit comments

Comments
 (0)