From ea63df1b22824387501aa39205fd1ba3813de2ad Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 1 May 2024 12:39:30 -0400 Subject: [PATCH] Fix intermittent time-based failure in delayed sidekiq spec 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. --- spec/chewy/strategy/delayed_sidekiq_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/chewy/strategy/delayed_sidekiq_spec.rb b/spec/chewy/strategy/delayed_sidekiq_spec.rb index c0d43e57..ae7a07dc 100644 --- a/spec/chewy/strategy/delayed_sidekiq_spec.rb +++ b/spec/chewy/strategy/delayed_sidekiq_spec.rb @@ -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)] ) @@ -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