From 216f4c99b0712ddfdc63997922f242f607e747a3 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Tue, 14 Aug 2018 12:35:20 +0200 Subject: [PATCH] Correct flaky spec --- spec/models/topic_timer_spec.rb | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/spec/models/topic_timer_spec.rb b/spec/models/topic_timer_spec.rb index b702f9a77e4..cd6f2e2b703 100644 --- a/spec/models/topic_timer_spec.rb +++ b/spec/models/topic_timer_spec.rb @@ -273,13 +273,17 @@ RSpec.describe TopicTimer, type: :model do topic: Fabricate(:topic, closed: true) ) - Fabricate(:topic_timer) + Fabricate(:topic_timer, execute_at: Time.zone.now + 1.hour) Fabricate(:topic_timer, execute_at: Time.zone.now - 1.hour, created_at: Time.zone.now - 2.hour ).topic.trash! + # creating topic timers already enqueues jobs + # let's delete them to test ensure_consistency! + Sidekiq::Worker.clear_all + expect { described_class.ensure_consistency! } .to change { Jobs::ToggleTopicClosed.jobs.count }.by(2) @@ -294,19 +298,22 @@ RSpec.describe TopicTimer, type: :model do expect(job_args["state"]).to eq(false) end - # intermittent failures - # it "should enqueue remind me jobs that have been missed" do - # reminder = Fabricate(:topic_timer, - # status_type: described_class.types[:reminder], - # execute_at: Time.zone.now - 1.hour, - # created_at: Time.zone.now - 2.hour - # ) + it "should enqueue remind me jobs that have been missed" do + reminder = Fabricate(:topic_timer, + status_type: described_class.types[:reminder], + execute_at: Time.zone.now - 1.hour, + created_at: Time.zone.now - 2.hour + ) - # expect { described_class.ensure_consistency! } - # .to change { Jobs::TopicReminder.jobs.count }.by(1) + # creating topic timers already enqueues jobs + # let's delete them to test ensure_consistency! + Sidekiq::Worker.clear_all - # job_args = Jobs::TopicReminder.jobs.first["args"].first - # expect(job_args["topic_timer_id"]).to eq(reminder.id) - # end + expect { described_class.ensure_consistency! } + .to change { Jobs::TopicReminder.jobs.count }.by(1) + + job_args = Jobs::TopicReminder.jobs.first["args"].first + expect(job_args["topic_timer_id"]).to eq(reminder.id) + end end end