aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-09-12 11:17:48 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-09-12 11:17:48 +0100
commite15138c9501a85bcafb0099b1a594035fadcc911 (patch)
treed87d49fdc8c7f27f1b0c43872c69417d067b4303
parentdfd1254dcb524adec0419ba1a84f1f4817f90d88 (diff)
Reminders are now unconditionally cleared when an alert is cleared.
-rw-r--r--lib/mauve/alert.rb20
-rw-r--r--test/tc_mauve_alert_changed.rb58
2 files changed, 75 insertions, 3 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 786ecab..ecea4e6 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -356,11 +356,25 @@ module Mauve
self.update_type = "cleared"
end
- unless save
+ if save
+ #
+ # Clear all reminders.
+ #
+ self.changes.all(:remind_at.not => nil, :at.lte => at, :update_type => "raised").each do |ac|
+ ac.remind_at = nil
+ ac.save
+ end
+
+ #
+ # Return true.
+ #
+ true
+ else
+ #
+ # Oops.
+ #
logger.error("Couldn't save #{self}")
false
- else
- true
end
end
diff --git a/test/tc_mauve_alert_changed.rb b/test/tc_mauve_alert_changed.rb
index ba31dd9..86f31d7 100644
--- a/test/tc_mauve_alert_changed.rb
+++ b/test/tc_mauve_alert_changed.rb
@@ -127,6 +127,64 @@ EOF
end
+ def test_only_set_one_alert_changed_on_a_reminder_after_multiple_raises_and_clears
+ config=<<EOF
+person("office_chat") {
+ all { true }
+}
+
+alert_group("test_group") {
+
+ level NORMAL
+
+ notify("office_chat") {
+ every 1.hour
+ during { working_hours? }
+ }
+
+}
+EOF
+
+
+ Configuration.current = ConfigurationBuilder.parse(config)
+
+ Server.instance.setup
+
+ alert = Alert.new(:source => "test", :alert_id => "test_alert", :summary => "test alert")
+
+ #
+ # Raise and clear the alert multiple times.
+ #
+ 5.times do
+ alert.raise!
+ Timecop.freeze(Time.now + 15.minutes)
+ alert.clear!
+ Timecop.freeze(Time.now + 15.minutes)
+ end
+
+ #
+ # No notification should have been sent, since it is the middle of the night
+ #
+ assert_equal(0,Server.instance.notification_buffer.length, "No notifications should have been sent.")
+ assert(alert.cleared?)
+
+ #
+ # Raise one final time.
+ #
+ alert.raise!
+ #
+ # Still no alerts should be sent.
+ #
+ assert_equal(0,Server.instance.notification_buffer.length, "No notifications should have been sent.")
+ assert(alert.raised?)
+
+ #
+ # Only one AlertChanged should be set now, with a reminder time of 8.30.
+ #
+ assert_equal(1, AlertChanged.all(:remind_at.not => nil).length, "Too many reminders are due to be sent.")
+
+ end
+
end