mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 10:33:38 +08:00
0c875cb4d5
Previously the problem check registry simply looked at the subclasses of ProblemCheck. This was causing some confusion in environments where eager loading is not enabled, as the registry would appear empty as a result of the classes never being referenced (and thus never loaded.) This PR changes the approach to a more explicit one. I followed other implementations (bookmarkable and hashtag autocomplete.) As a bonus, this now has a neat plugin entry point as well.
80 lines
2.1 KiB
Ruby
80 lines
2.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Jobs::RunProblemChecks do
|
|
around do |example|
|
|
ProblemCheck::ScheduledCheck =
|
|
Class.new(ProblemCheck) do
|
|
self.perform_every = 30.minutes
|
|
|
|
def call = []
|
|
end
|
|
|
|
ProblemCheck::NonScheduledCheck = Class.new(ProblemCheck) { def call = [] }
|
|
|
|
stub_const(
|
|
ProblemCheck,
|
|
"CORE_PROBLEM_CHECKS",
|
|
[ProblemCheck::ScheduledCheck, ProblemCheck::NonScheduledCheck],
|
|
&example
|
|
)
|
|
|
|
Discourse.redis.flushdb
|
|
AdminDashboardData.reset_problem_checks
|
|
|
|
ProblemCheck.send(:remove_const, "ScheduledCheck")
|
|
ProblemCheck.send(:remove_const, "NonScheduledCheck")
|
|
end
|
|
|
|
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: :run_problem_check,
|
|
args: {
|
|
check_identifier: "scheduled_check",
|
|
},
|
|
) { described_class.new.execute([]) }
|
|
end
|
|
end
|
|
|
|
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: :run_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: :run_problem_check,
|
|
args: {
|
|
check_identifier: "non_scheduled_check",
|
|
},
|
|
) { described_class.new.execute([]) }
|
|
end
|
|
end
|
|
|
|
it "does not schedule non-scheduled checks" do
|
|
expect_not_enqueued_with(
|
|
job: :run_problem_check,
|
|
args: {
|
|
check_identifier: "non_scheduled_check",
|
|
},
|
|
) { described_class.new.execute([]) }
|
|
end
|
|
end
|