aboutsummaryrefslogtreecommitdiff
path: root/test/tc_mauve_person.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-09-06 11:05:30 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-09-06 11:05:30 +0100
commita704ace65369c4c9ca6fc71c0f5106203012bf16 (patch)
tree79e290515be17a1a38d5b6d7a7b6e0715597cb37 /test/tc_mauve_person.rb
parent47e71be469815a725d7e643dfcc95eb1a3012c89 (diff)
Fixed up suppression some more, so it works.
Diffstat (limited to 'test/tc_mauve_person.rb')
-rw-r--r--test/tc_mauve_person.rb85
1 files changed, 81 insertions, 4 deletions
diff --git a/test/tc_mauve_person.rb b/test/tc_mauve_person.rb
index c659f00..30051b0 100644
--- a/test/tc_mauve_person.rb
+++ b/test/tc_mauve_person.rb
@@ -83,17 +83,94 @@ EOF
person.send_alert(alert.level, alert)
- assert_equal(suppressed, person.suppressed?)
+ assert_equal(suppressed, person.suppressed?, "Suppressed (or not) when it should (or shouldn't) be at #{Time.now}.")
if notification_sent
- assert_equal(1, $sent_notifications.length, "Notification not sent when it should have been.")
+ assert_equal(1, $sent_notifications.length, "Notification not sent when it should have been at #{Time.now}.")
#
# Pop the notification off the buffer.
#
last_notification_sent_at = $sent_notifications.pop
- assert_equal(Time.now, person.notification_thresholds[60][-1], "Notification thresholds not updated")
+ assert_equal(Time.now, person.notification_thresholds[60][-1], "Notification thresholds not updated at #{Time.now}.")
else
- assert_equal(0, $sent_notifications.length, "Notification sent when it should not have been.")
+ assert_equal(0, $sent_notifications.length, "Notification sent when it should not have been at #{Time.now}.")
+ end
+
+ logger_pop
+ end
+
+ end
+
+ def test_send_alert_when_only_one_blargh
+ #
+ # Allows us to pick up notifications sent.
+ #
+ $sent_notifications = []
+
+ #
+ # This configuration is a bit different. We only want one alert per
+ # minute.
+ #
+ config =<<EOF
+person ("test") {
+ all { $sent_notifications << Time.now ; true }
+ suppress_notifications_after( 1 => 1.minute )
+}
+
+alert_group("default") {
+ level URGENT
+
+ notify("test") {
+ every 10.seconds
+ }
+}
+EOF
+
+ Configuration.current = ConfigurationBuilder.parse(config)
+ Server.instance.setup
+
+ person = Configuration.current.people["test"]
+
+ alert = Alert.new(
+ :alert_id => "test",
+ :source => "test",
+ :subject => "test"
+ )
+
+ alert.raise!
+ assert_equal(false, person.suppressed?, "Person suppressed before we even begin!")
+
+ start_time = Time.now
+
+ #
+ # 1 alerts every 60 seconds.
+ #
+ [ [0, true, true],
+ [5, false, true],
+ [15, false, true],
+ [30, false, true],
+ [60, true, true], # One minute after starting -- should send an alert, but still be suppressed.
+ [90, false, true],
+ [120, true, true] # Two minutes after starting -- should send an alert, but still be suppressed.
+ ].each do |offset, notification_sent, suppressed|
+ #
+ # Advance in to the future!
+ #
+ Timecop.freeze(start_time + offset)
+
+ person.send_alert(alert.level, alert)
+
+ assert_equal(suppressed, person.should_suppress?, "Suppressed (or not) when it should (or shouldn't) be at #{Time.now}.")
+
+ if notification_sent
+ assert_equal(1, $sent_notifications.length, "Notification not sent when it should have been at #{Time.now}.")
+ #
+ # Pop the notification off the buffer.
+ #
+ last_notification_sent_at = $sent_notifications.pop
+ assert_equal(Time.now, person.notification_thresholds[60][-1], "Notification thresholds not updated at #{Time.now}.")
+ else
+ assert_equal(0, $sent_notifications.length, "Notification sent when it should not have been at #{Time.now}.")
end
logger_pop