mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 17:53:55 +08:00
### What is this change? Multi-target problem checks can dynamically return targets to check for. For example, the groups with SMTP enabled can change, LLM models can be disabled, etc. which affects whether they are checked or not. This introduces a mechanism for cleaning up trackers that point to targets that are no longer in the target list.
31 lines
1.1 KiB
Ruby
Vendored
31 lines
1.1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe Jobs::CleanupProblemCheckTrackers do
|
|
around do |example|
|
|
ProblemCheck::MultiTargetCheck =
|
|
Class.new(ProblemCheck) do
|
|
self.perform_every = 30.minutes
|
|
self.targets = -> { %w[foo bar] }
|
|
end
|
|
|
|
stub_const(ProblemCheck, "CORE_PROBLEM_CHECKS", [ProblemCheck::MultiTargetCheck], &example)
|
|
|
|
ProblemCheck.send(:remove_const, "MultiTargetCheck")
|
|
end
|
|
|
|
context "when a tracker has an outdated target" do
|
|
before do
|
|
ProblemCheckTracker.create!(identifier: "multi_target_check", target: "foo").problem!
|
|
ProblemCheckTracker.create!(identifier: "multi_target_check", target: "bar").problem!
|
|
ProblemCheckTracker.create!(identifier: "multi_target_check", target: "baz").problem!
|
|
end
|
|
|
|
it "deletes trackers with non-existing targets together with any admin notices" do
|
|
expect { described_class.new.execute([]) }.to change {
|
|
ProblemCheckTracker.pluck(:target)
|
|
}.from(contain_exactly("foo", "bar", "baz")).to(contain_exactly("foo", "bar")).and change {
|
|
AdminNotice.count
|
|
}.by(-1)
|
|
end
|
|
end
|
|
end
|