2021-12-19 18:59:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Jobs::ProblemChecks do
|
2024-02-22 22:20:32 -05:00
|
|
|
before do
|
|
|
|
::ProblemCheck::ScheduledCheck =
|
|
|
|
Class.new(ProblemCheck) do
|
|
|
|
self.perform_every = 30.minutes
|
|
|
|
|
|
|
|
def call = []
|
|
|
|
end
|
|
|
|
|
|
|
|
::ProblemCheck::NonScheduledCheck = Class.new(ProblemCheck) { def call = [] }
|
|
|
|
end
|
2023-11-02 21:05:29 -04:00
|
|
|
|
2021-12-19 18:59:11 -05:00
|
|
|
after do
|
|
|
|
Discourse.redis.flushdb
|
|
|
|
AdminDashboardData.reset_problem_checks
|
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
ProblemCheck.send(:remove_const, "ScheduledCheck")
|
|
|
|
ProblemCheck.send(:remove_const, "NonScheduledCheck")
|
2023-11-05 19:57:02 -05:00
|
|
|
end
|
|
|
|
|
2024-02-26 22:17:39 -05:00
|
|
|
context "when the tracker determines the check is ready to run" do
|
|
|
|
before do
|
|
|
|
ProblemCheckTracker.create!(identifier: "scheduled_check", next_run_at: 5.minutes.ago)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "schedules the individual scheduled checks" do
|
|
|
|
expect_enqueued_with(job: :problem_check, args: { check_identifier: "scheduled_check" }) do
|
|
|
|
described_class.new.execute([])
|
|
|
|
end
|
2021-12-19 18:59:11 -05:00
|
|
|
end
|
2024-02-22 22:20:32 -05:00
|
|
|
end
|
2021-12-19 18:59:11 -05:00
|
|
|
|
2024-02-26 22:17:39 -05:00
|
|
|
context "when the tracker determines the check shouldn't run yet" do
|
|
|
|
before do
|
|
|
|
ProblemCheckTracker.create!(identifier: "scheduled_check", next_run_at: 5.minutes.from_now)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not schedule any check" do
|
|
|
|
expect_not_enqueued_with(
|
|
|
|
job: :problem_check,
|
|
|
|
args: {
|
|
|
|
check_identifier: "scheduled_check",
|
|
|
|
},
|
|
|
|
) { described_class.new.execute([]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when dealing with a non-scheduled check" do
|
|
|
|
before { ProblemCheckTracker.create!(identifier: "non_scheduled_check", next_run_at: nil) }
|
|
|
|
|
|
|
|
it "does not schedule any check" do
|
|
|
|
expect_not_enqueued_with(
|
|
|
|
job: :problem_check,
|
|
|
|
args: {
|
|
|
|
check_identifier: "non_scheduled_check",
|
|
|
|
},
|
|
|
|
) { described_class.new.execute([]) }
|
|
|
|
end
|
2021-12-19 18:59:11 -05:00
|
|
|
end
|
2024-02-25 23:08:12 -05:00
|
|
|
|
|
|
|
it "does not schedule non-scheduled checks" do
|
|
|
|
expect_not_enqueued_with(
|
|
|
|
job: :problem_check,
|
|
|
|
args: {
|
|
|
|
check_identifier: "non_scheduled_check",
|
|
|
|
},
|
|
|
|
) { described_class.new.execute([]) }
|
|
|
|
end
|
2021-12-19 18:59:11 -05:00
|
|
|
end
|