From ea63df1b22824387501aa39205fd1ba3813de2ad Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 1 May 2024 12:39:30 -0400 Subject: [PATCH 1/2] 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 From a68d43cde008655f835cc95c7ee108bcc10a7992 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 1 May 2024 13:03:51 -0400 Subject: [PATCH 2/2] Add changelog notes --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca237464..bfe3a60f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ ### Bugs Fixed +* [#947](https://github.com/toptal/chewy/pull/947): Fix intermittent time-based failure in delayed sidekiq spec. ([@mjankowski][]) + ## 7.5.1 (2024-01-30) ### New Features