2021-12-20 07:59:11 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-03-07 12:26:58 +08:00
|
|
|
RSpec.describe Jobs::RunProblemChecks do
|
2024-03-28 14:00:47 +08:00
|
|
|
around do |example|
|
2024-03-07 12:26:58 +08:00
|
|
|
ProblemCheck::ScheduledCheck =
|
2024-02-23 11:20:32 +08:00
|
|
|
Class.new(ProblemCheck) do
|
|
|
|
self.perform_every = 30.minutes
|
|
|
|
|
|
|
|
def call = []
|
|
|
|
end
|
|
|
|
|
2024-03-07 12:26:58 +08:00
|
|
|
ProblemCheck::NonScheduledCheck = Class.new(ProblemCheck) { def call = [] }
|
2023-11-03 09:05:29 +08:00
|
|
|
|
2024-09-18 10:11:52 +08:00
|
|
|
ProblemCheck::DisabledCheck =
|
|
|
|
Class.new(ProblemCheck) do
|
|
|
|
self.perform_every = 30.minutes
|
|
|
|
self.enabled = false
|
|
|
|
|
|
|
|
def call = []
|
|
|
|
end
|
|
|
|
|
2024-03-28 14:00:47 +08:00
|
|
|
stub_const(
|
|
|
|
ProblemCheck,
|
|
|
|
"CORE_PROBLEM_CHECKS",
|
2024-09-18 10:11:52 +08:00
|
|
|
[ProblemCheck::ScheduledCheck, ProblemCheck::NonScheduledCheck, ProblemCheck::DisabledCheck],
|
2024-03-28 14:00:47 +08:00
|
|
|
&example
|
|
|
|
)
|
|
|
|
|
2024-02-23 11:20:32 +08:00
|
|
|
ProblemCheck.send(:remove_const, "ScheduledCheck")
|
|
|
|
ProblemCheck.send(:remove_const, "NonScheduledCheck")
|
2024-09-18 10:11:52 +08:00
|
|
|
ProblemCheck.send(:remove_const, "DisabledCheck")
|
2023-11-06 08:57:02 +08:00
|
|
|
end
|
|
|
|
|
2024-02-27 11:17:39 +08: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
|
2024-03-07 13:31:59 +08:00
|
|
|
expect_enqueued_with(
|
|
|
|
job: :run_problem_check,
|
|
|
|
args: {
|
|
|
|
check_identifier: "scheduled_check",
|
|
|
|
},
|
|
|
|
) { described_class.new.execute([]) }
|
2021-12-20 07:59:11 +08:00
|
|
|
end
|
2024-02-23 11:20:32 +08:00
|
|
|
end
|
2021-12-20 07:59:11 +08:00
|
|
|
|
2024-02-27 11:17:39 +08: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(
|
2024-03-07 12:26:58 +08:00
|
|
|
job: :run_problem_check,
|
2024-02-27 11:17:39 +08:00
|
|
|
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(
|
2024-03-07 12:26:58 +08:00
|
|
|
job: :run_problem_check,
|
2024-02-27 11:17:39 +08:00
|
|
|
args: {
|
|
|
|
check_identifier: "non_scheduled_check",
|
|
|
|
},
|
|
|
|
) { described_class.new.execute([]) }
|
|
|
|
end
|
2021-12-20 07:59:11 +08:00
|
|
|
end
|
2024-02-26 12:08:12 +08:00
|
|
|
|
2024-09-18 10:11:52 +08:00
|
|
|
context "when dealing with a disabled check" do
|
|
|
|
before { ProblemCheckTracker.create!(identifier: "disabled_check", next_run_at: nil) }
|
|
|
|
|
|
|
|
it "does not schedule any check" do
|
|
|
|
expect_not_enqueued_with(
|
|
|
|
job: :run_problem_check,
|
|
|
|
args: {
|
|
|
|
check_identifier: "disabled_check",
|
|
|
|
},
|
|
|
|
) { described_class.new.execute([]) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when dealing with an uninstalled check" do
|
|
|
|
before { ProblemCheckTracker.create!(identifier: "uninstalled_check", next_run_at: nil) }
|
|
|
|
|
|
|
|
it "does not schedule any check" do
|
|
|
|
expect_not_enqueued_with(
|
|
|
|
job: :run_problem_check,
|
|
|
|
args: {
|
|
|
|
check_identifier: "uninstalled_check",
|
|
|
|
},
|
|
|
|
) { described_class.new.execute([]) }
|
|
|
|
end
|
2024-02-26 12:08:12 +08:00
|
|
|
end
|
2021-12-20 07:59:11 +08:00
|
|
|
end
|