2023-11-02 21:05:29 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-03-06 23:26:58 -05:00
|
|
|
RSpec.describe Jobs::RunProblemCheck do
|
2024-03-28 02:00:47 -04:00
|
|
|
after { Discourse.redis.flushdb }
|
2023-11-05 19:57:02 -05:00
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
context "when there are problems" do
|
2024-03-28 02:00:47 -04:00
|
|
|
around do |example|
|
2024-03-06 23:26:58 -05:00
|
|
|
ProblemCheck::TestCheck =
|
|
|
|
Class.new(ProblemCheck) do
|
2024-02-26 22:17:39 -05:00
|
|
|
self.perform_every = 30.minutes
|
2024-02-22 22:20:32 -05:00
|
|
|
self.max_retries = 0
|
|
|
|
|
|
|
|
def call
|
|
|
|
[
|
2024-03-06 23:26:58 -05:00
|
|
|
ProblemCheck::Problem.new("Big problem"),
|
|
|
|
ProblemCheck::Problem.new(
|
2024-02-22 22:20:32 -05:00
|
|
|
"Yuge problem",
|
|
|
|
priority: "high",
|
|
|
|
identifier: "config_is_a_mess",
|
|
|
|
),
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
2024-03-28 02:00:47 -04:00
|
|
|
|
|
|
|
stub_const(ProblemCheck, "CORE_PROBLEM_CHECKS", [ProblemCheck::TestCheck], &example)
|
|
|
|
|
|
|
|
ProblemCheck.send(:remove_const, "TestCheck")
|
2023-11-02 21:05:29 -04:00
|
|
|
end
|
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
it "adds the messages to the Redis problems array" do
|
|
|
|
described_class.new.execute(check_identifier: :test_check)
|
2023-11-02 21:05:29 -04:00
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
problems = AdminDashboardData.load_found_scheduled_check_problems
|
2023-11-02 21:05:29 -04:00
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
expect(problems.map(&:to_s)).to contain_exactly("Big problem", "Yuge problem")
|
|
|
|
end
|
2023-11-02 21:05:29 -04:00
|
|
|
end
|
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
context "with multiple problems with the same identifier" do
|
2024-03-28 02:00:47 -04:00
|
|
|
around do |example|
|
2024-03-06 23:26:58 -05:00
|
|
|
ProblemCheck::TestCheck =
|
|
|
|
Class.new(ProblemCheck) do
|
2024-02-26 22:17:39 -05:00
|
|
|
self.perform_every = 30.minutes
|
2024-02-22 22:20:32 -05:00
|
|
|
self.max_retries = 0
|
|
|
|
|
|
|
|
def call
|
|
|
|
[
|
2024-03-06 23:26:58 -05:00
|
|
|
ProblemCheck::Problem.new(
|
2024-02-22 22:20:32 -05:00
|
|
|
"Yuge problem",
|
|
|
|
priority: "high",
|
|
|
|
identifier: "config_is_a_mess",
|
|
|
|
),
|
2024-03-06 23:26:58 -05:00
|
|
|
ProblemCheck::Problem.new(
|
2024-02-22 22:20:32 -05:00
|
|
|
"Nasty problem",
|
|
|
|
priority: "high",
|
|
|
|
identifier: "config_is_a_mess",
|
|
|
|
),
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
2024-03-28 02:00:47 -04:00
|
|
|
|
|
|
|
stub_const(ProblemCheck, "CORE_PROBLEM_CHECKS", [ProblemCheck::TestCheck], &example)
|
|
|
|
|
|
|
|
ProblemCheck.send(:remove_const, "TestCheck")
|
2023-11-02 21:05:29 -04:00
|
|
|
end
|
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
it "does not add the same problem twice" do
|
|
|
|
described_class.new.execute(check_identifier: :test_check)
|
|
|
|
|
|
|
|
problems = AdminDashboardData.load_found_scheduled_check_problems
|
2023-11-02 21:05:29 -04:00
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
expect(problems.map(&:to_s)).to match_array(["Yuge problem"])
|
2023-11-05 19:57:02 -05:00
|
|
|
end
|
2024-02-22 22:20:32 -05:00
|
|
|
end
|
2023-11-05 19:57:02 -05:00
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
context "when there are retries remaining" do
|
2024-03-28 02:00:47 -04:00
|
|
|
around do |example|
|
2024-03-06 23:26:58 -05:00
|
|
|
ProblemCheck::TestCheck =
|
|
|
|
Class.new(ProblemCheck) do
|
2024-02-26 22:17:39 -05:00
|
|
|
self.perform_every = 30.minutes
|
2024-02-22 22:20:32 -05:00
|
|
|
self.max_retries = 2
|
2023-11-05 19:57:02 -05:00
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
def call
|
2024-03-06 23:26:58 -05:00
|
|
|
[ProblemCheck::Problem.new("Yuge problem")]
|
2024-02-22 22:20:32 -05:00
|
|
|
end
|
|
|
|
end
|
2024-03-28 02:00:47 -04:00
|
|
|
|
|
|
|
stub_const(ProblemCheck, "CORE_PROBLEM_CHECKS", [ProblemCheck::TestCheck], &example)
|
|
|
|
|
|
|
|
ProblemCheck.send(:remove_const, "TestCheck")
|
2024-02-22 22:20:32 -05:00
|
|
|
end
|
2023-11-05 19:57:02 -05:00
|
|
|
|
2024-02-26 22:17:39 -05: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-22 22:20:32 -05:00
|
|
|
it "schedules a retry" do
|
|
|
|
expect_enqueued_with(
|
2024-03-07 00:31:59 -05:00
|
|
|
job: :run_problem_check,
|
2024-02-22 22:20:32 -05:00
|
|
|
args: {
|
|
|
|
check_identifier: :test_check,
|
|
|
|
retry_count: 1,
|
|
|
|
},
|
|
|
|
) { described_class.new.execute(check_identifier: :test_check) }
|
2023-11-05 19:57:02 -05:00
|
|
|
end
|
2024-02-22 22:20:32 -05:00
|
|
|
end
|
2023-11-05 19:57:02 -05:00
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
context "when there are no retries remaining" do
|
2024-03-28 02:00:47 -04:00
|
|
|
around do |example|
|
2024-03-06 23:26:58 -05:00
|
|
|
ProblemCheck::TestCheck =
|
|
|
|
Class.new(ProblemCheck) do
|
2024-02-26 22:17:39 -05:00
|
|
|
self.perform_every = 30.minutes
|
2024-02-22 22:20:32 -05:00
|
|
|
self.max_retries = 1
|
|
|
|
|
|
|
|
def call
|
2024-03-06 23:26:58 -05:00
|
|
|
[ProblemCheck::Problem.new("Yuge problem")]
|
2024-02-22 22:20:32 -05:00
|
|
|
end
|
|
|
|
end
|
2024-03-28 02:00:47 -04:00
|
|
|
|
|
|
|
stub_const(ProblemCheck, "CORE_PROBLEM_CHECKS", [ProblemCheck::TestCheck], &example)
|
|
|
|
|
|
|
|
ProblemCheck.send(:remove_const, "TestCheck")
|
2024-02-22 22:20:32 -05:00
|
|
|
end
|
2023-11-05 19:57:02 -05:00
|
|
|
|
2024-02-26 22:17:39 -05: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-22 22:20:32 -05:00
|
|
|
it "does not schedule a retry" do
|
2024-03-07 00:31:59 -05:00
|
|
|
expect_not_enqueued_with(job: :run_problem_check) do
|
2024-02-26 22:17:39 -05:00
|
|
|
described_class.new.execute(check_identifier: :test_check, retry_count: 1)
|
2024-02-22 22:20:32 -05:00
|
|
|
end
|
2023-11-05 19:57:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
context "when the check unexpectedly errors out" do
|
2024-03-28 02:00:47 -04:00
|
|
|
around do |example|
|
2024-03-06 23:26:58 -05:00
|
|
|
ProblemCheck::TestCheck =
|
|
|
|
Class.new(ProblemCheck) do
|
2024-02-22 22:20:32 -05:00
|
|
|
self.max_retries = 1
|
|
|
|
|
|
|
|
def call
|
|
|
|
raise StandardError.new("Something went wrong")
|
|
|
|
end
|
|
|
|
end
|
2024-03-28 02:00:47 -04:00
|
|
|
|
|
|
|
stub_const(ProblemCheck, "CORE_PROBLEM_CHECKS", [ProblemCheck::TestCheck], &example)
|
|
|
|
|
|
|
|
ProblemCheck.send(:remove_const, "TestCheck")
|
2023-11-02 21:05:29 -04:00
|
|
|
end
|
|
|
|
|
2024-02-22 22:20:32 -05: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-02 21:05:29 -04:00
|
|
|
end
|
|
|
|
end
|