From c5c9714b04299991502c753248299bda81f80a94 Mon Sep 17 00:00:00 2001 From: Ankitha Damodara Date: Wed, 3 Jul 2024 09:49:28 +0100 Subject: [PATCH] fix flaky tests --- spec/lib/que/locker_spec.rb | 7 +++++-- spec/lib/que/middleware/queue_collector_spec.rb | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/lib/que/locker_spec.rb b/spec/lib/que/locker_spec.rb index 08cc4a7d..505925db 100644 --- a/spec/lib/que/locker_spec.rb +++ b/spec/lib/que/locker_spec.rb @@ -94,8 +94,11 @@ def expect_to_lock_with(cursor:) context "with non-zero cursor expiry" do let(:cursor_expiry) { 5 } - before { allow(locker).to receive(:monotonic_now) { @epoch } } - + before do + # we need this to avoid flakiness during resetting the cursor + locker.instance_variable_get(:@queue_expires_at)[queue] = Process.clock_gettime(Process::CLOCK_MONOTONIC) + cursor_expiry + allow(locker).to receive(:monotonic_now) { @epoch } + end # This test simulates the repeated locking of jobs. We're trying to prove that # the locker will use the previous jobs ID as a cursor until the expiry has # elapsed, after which we'll reset. diff --git a/spec/lib/que/middleware/queue_collector_spec.rb b/spec/lib/que/middleware/queue_collector_spec.rb index 6d804f3a..aa510213 100644 --- a/spec/lib/que/middleware/queue_collector_spec.rb +++ b/spec/lib/que/middleware/queue_collector_spec.rb @@ -4,7 +4,7 @@ RSpec.describe Que::Middleware::QueueCollector do subject(:collector) { described_class.new(->(_env) { nil }, options) } - let(:options) { {} } + let(:options) { {refresh_interval: 1.second} } let(:now) { postgres_now } let(:due_now_delay) { 1000.0 } let(:due_later_than_now_delay) { due_now_delay / 2 }