Skip to content

Commit

Permalink
Fix intermittent time-based failure in delayed sidekiq spec
Browse files Browse the repository at this point in the history
This example was previously failing when it was run at exactly an "even"
10 second increment time. For example, it would fail at "12:00:10", but
pass at "12:00:09" and "12:00:11". This leads to intermittent failures
on CI (presumably around ~10% of runs).

Updated to use a helper method in the spec which more closely mirrors
the scheduler code.
  • Loading branch information
mjankowski committed May 1, 2024
1 parent 7e65698 commit ea63df1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion spec/chewy/strategy/delayed_sidekiq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
expect(Sidekiq::Client).to receive(:push).with(
hash_including(
'queue' => 'chewy',
'at' => (Time.current.to_i.ceil(-1) + 2.seconds).to_i,
'at' => expected_at_time.to_i,
'class' => Chewy::Strategy::DelayedSidekiq::Worker,
'args' => ['CitiesIndex', an_instance_of(Integer)]
)
Expand All @@ -62,6 +62,11 @@
end
end
end

def expected_at_time
target = described_class::Scheduler::DEFAULT_LATENCY.seconds.from_now.to_i
target - (target % described_class::Scheduler::DEFAULT_LATENCY) + described_class::Scheduler::DEFAULT_MARGIN.seconds
end
end

context 'with custom config' do
Expand Down

0 comments on commit ea63df1

Please sign in to comment.