2023-11-03 09:05:29 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-03-07 12:26:58 +08:00
|
|
|
RSpec.describe Jobs::RunProblemCheck do
|
2024-03-28 14:00:47 +08:00
|
|
|
after { Discourse.redis.flushdb }
|
2023-11-06 08:57:02 +08:00
|
|
|
|
2024-02-23 11:20:32 +08:00
|
|
|
context "when there are problems" do
|
2024-03-28 14:00:47 +08:00
|
|
|
around do |example|
|
2024-03-07 12:26:58 +08:00
|
|
|
ProblemCheck::TestCheck =
|
|
|
|
Class.new(ProblemCheck) do
|
2024-02-27 11:17:39 +08:00
|
|
|
self.perform_every = 30.minutes
|
2024-02-23 11:20:32 +08:00
|
|
|
self.max_retries = 0
|
|
|
|
|
|
|
|
def call
|
|
|
|
[
|
2024-03-07 12:26:58 +08:00
|
|
|
ProblemCheck::Problem.new("Big problem"),
|
|
|
|
ProblemCheck::Problem.new(
|
2024-02-23 11:20:32 +08:00
|
|
|
"Yuge problem",
|
|
|
|
priority: "high",
|
|
|
|
identifier: "config_is_a_mess",
|
|
|
|
),
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
2024-03-28 14:00:47 +08:00
|
|
|
|
|
|
|
stub_const(ProblemCheck, "CORE_PROBLEM_CHECKS", [ProblemCheck::TestCheck], &example)
|
|
|
|
|
|
|
|
ProblemCheck.send(:remove_const, "TestCheck")
|
2023-11-03 09:05:29 +08:00
|
|
|
end
|
|
|
|
|
2024-05-23 09:29:08 +08:00
|
|
|
it "updates the problem check tracker" do
|
|
|
|
expect {
|
|
|
|
described_class.new.execute(check_identifier: :test_check, retry_count: 0)
|
|
|
|
}.to change { ProblemCheckTracker.failing.count }.by(1)
|
2023-11-06 08:57:02 +08:00
|
|
|
end
|
2024-02-23 11:20:32 +08:00
|
|
|
end
|
2023-11-06 08:57:02 +08:00
|
|
|
|
2024-02-23 11:20:32 +08:00
|
|
|
context "when there are retries remaining" do
|
2024-03-28 14:00:47 +08:00
|
|
|
around do |example|
|
2024-03-07 12:26:58 +08:00
|
|
|
ProblemCheck::TestCheck =
|
|
|
|
Class.new(ProblemCheck) do
|
2024-02-27 11:17:39 +08:00
|
|
|
self.perform_every = 30.minutes
|
2024-02-23 11:20:32 +08:00
|
|
|
self.max_retries = 2
|
2023-11-06 08:57:02 +08:00
|
|
|
|
2024-02-23 11:20:32 +08:00
|
|
|
def call
|
2024-03-07 12:26:58 +08:00
|
|
|
[ProblemCheck::Problem.new("Yuge problem")]
|
2024-02-23 11:20:32 +08:00
|
|
|
end
|
|
|
|
end
|
2024-03-28 14:00:47 +08:00
|
|
|
|
|
|
|
stub_const(ProblemCheck, "CORE_PROBLEM_CHECKS", [ProblemCheck::TestCheck], &example)
|
|
|
|
|
|
|
|
ProblemCheck.send(:remove_const, "TestCheck")
|
2024-02-23 11:20:32 +08:00
|
|
|
end
|
2023-11-06 08:57:02 +08:00
|
|
|
|
2024-02-27 11:17:39 +08:00
|
|
|
it "does not yet update the problem check tracker" do
|
|
|
|
expect {
|
|
|
|
described_class.new.execute(check_identifier: :test_check, retry_count: 1)
|
|
|
|
}.not_to change { ProblemCheckTracker.where("blips > ?", 0).count }
|
|
|
|
end
|
|
|
|
|
2024-02-23 11:20:32 +08:00
|
|
|
it "schedules a retry" do
|
|
|
|
expect_enqueued_with(
|
2024-03-07 13:31:59 +08:00
|
|
|
job: :run_problem_check,
|
2024-02-23 11:20:32 +08:00
|
|
|
args: {
|
|
|
|
check_identifier: :test_check,
|
|
|
|
retry_count: 1,
|
|
|
|
},
|
|
|
|
) { described_class.new.execute(check_identifier: :test_check) }
|
2023-11-06 08:57:02 +08:00
|
|
|
end
|
2024-02-23 11:20:32 +08:00
|
|
|
end
|
2023-11-06 08:57:02 +08:00
|
|
|
|
2024-02-23 11:20:32 +08:00
|
|
|
context "when there are no retries remaining" do
|
2024-03-28 14:00:47 +08:00
|
|
|
around do |example|
|
2024-03-07 12:26:58 +08:00
|
|
|
ProblemCheck::TestCheck =
|
|
|
|
Class.new(ProblemCheck) do
|
2024-02-27 11:17:39 +08:00
|
|
|
self.perform_every = 30.minutes
|
2024-02-23 11:20:32 +08:00
|
|
|
self.max_retries = 1
|
|
|
|
|
|
|
|
def call
|
2024-03-07 12:26:58 +08:00
|
|
|
[ProblemCheck::Problem.new("Yuge problem")]
|
2024-02-23 11:20:32 +08:00
|
|
|
end
|
|
|
|
end
|
2024-03-28 14:00:47 +08:00
|
|
|
|
|
|
|
stub_const(ProblemCheck, "CORE_PROBLEM_CHECKS", [ProblemCheck::TestCheck], &example)
|
|
|
|
|
|
|
|
ProblemCheck.send(:remove_const, "TestCheck")
|
2024-02-23 11:20:32 +08:00
|
|
|
end
|
2023-11-06 08:57:02 +08:00
|
|
|
|
2024-02-27 11:17:39 +08:00
|
|
|
it "updates the problem check tracker" do
|
|
|
|
expect {
|
|
|
|
described_class.new.execute(check_identifier: :test_check, retry_count: 1)
|
|
|
|
}.to change { ProblemCheckTracker.where("blips > ?", 0).count }.by(1)
|
|
|
|
end
|
|
|
|
|
2024-02-23 11:20:32 +08:00
|
|
|
it "does not schedule a retry" do
|
2024-03-07 13:31:59 +08:00
|
|
|
expect_not_enqueued_with(job: :run_problem_check) do
|
2024-02-27 11:17:39 +08:00
|
|
|
described_class.new.execute(check_identifier: :test_check, retry_count: 1)
|
2024-02-23 11:20:32 +08:00
|
|
|
end
|
2023-11-06 08:57:02 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-02-23 11:20:32 +08:00
|
|
|
context "when the check unexpectedly errors out" do
|
2024-03-28 14:00:47 +08:00
|
|
|
around do |example|
|
2024-03-07 12:26:58 +08:00
|
|
|
ProblemCheck::TestCheck =
|
|
|
|
Class.new(ProblemCheck) do
|
2024-02-23 11:20:32 +08:00
|
|
|
self.max_retries = 1
|
|
|
|
|
|
|
|
def call
|
|
|
|
raise StandardError.new("Something went wrong")
|
|
|
|
end
|
|
|
|
end
|
2024-03-28 14:00:47 +08:00
|
|
|
|
|
|
|
stub_const(ProblemCheck, "CORE_PROBLEM_CHECKS", [ProblemCheck::TestCheck], &example)
|
|
|
|
|
|
|
|
ProblemCheck.send(:remove_const, "TestCheck")
|
2023-11-03 09:05:29 +08:00
|
|
|
end
|
|
|
|
|
2024-02-23 11:20:32 +08:00
|
|
|
it "does not add a problem to the Redis array" do
|
|
|
|
described_class.new.execute(check_identifier: :test_check)
|
|
|
|
|
|
|
|
expect(AdminDashboardData.load_found_scheduled_check_problems).to be_empty
|
|
|
|
end
|
2023-11-03 09:05:29 +08:00
|
|
|
end
|
|
|
|
end
|