2021-12-20 07:59:11 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Jobs::ProblemChecks do
|
2023-11-03 09:05:29 +08:00
|
|
|
before { Jobs.run_immediately! }
|
|
|
|
|
2021-12-20 07:59:11 +08:00
|
|
|
after do
|
|
|
|
Discourse.redis.flushdb
|
|
|
|
AdminDashboardData.reset_problem_checks
|
|
|
|
end
|
|
|
|
|
2023-11-06 08:57:02 +08:00
|
|
|
class TestCheck
|
|
|
|
def self.max_retries = 0
|
|
|
|
def self.retry_wait = 0.seconds
|
|
|
|
end
|
|
|
|
|
2021-12-20 07:59:11 +08:00
|
|
|
it "starts with a blank slate every time the checks are run to avoid duplicate problems and to clear no longer firing problems" do
|
|
|
|
problem_should_fire = true
|
2023-11-03 09:05:29 +08:00
|
|
|
AdminDashboardData.reset_problem_checks
|
2023-11-06 08:57:02 +08:00
|
|
|
AdminDashboardData.add_scheduled_problem_check(:test_identifier, TestCheck) do
|
2021-12-20 07:59:11 +08:00
|
|
|
if problem_should_fire
|
|
|
|
problem_should_fire = false
|
|
|
|
AdminDashboardData::Problem.new("yuge problem", priority: "high")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
described_class.new.execute(nil)
|
|
|
|
expect(AdminDashboardData.load_found_scheduled_check_problems.count).to eq(1)
|
|
|
|
described_class.new.execute(nil)
|
|
|
|
expect(AdminDashboardData.load_found_scheduled_check_problems.count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|