diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-08-31 12:19:48 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-08-31 12:19:48 +0100 |
commit | b87b69ca3fb266bdb5de88b9e77da54e23e370a5 (patch) | |
tree | 94698670ecd9b8562ae41b0ab793fac821f91f97 /test | |
parent | 36543941d784715e962599f7bf73f4680387e610 (diff) |
Fixed up alert suppression to be less jumpy
Diffstat (limited to 'test')
-rw-r--r-- | test/tc_mauve_alert.rb | 6 | ||||
-rw-r--r-- | test/tc_mauve_alert_changed.rb | 2 | ||||
-rw-r--r-- | test/tc_mauve_notification.rb | 27 | ||||
-rw-r--r-- | test/tc_mauve_person.rb | 86 | ||||
-rw-r--r-- | test/test_mauve.rb | 13 | ||||
-rw-r--r-- | test/th_mauve.rb | 2 |
6 files changed, 114 insertions, 22 deletions
diff --git a/test/tc_mauve_alert.rb b/test/tc_mauve_alert.rb index f85236e..a9aef5f 100644 --- a/test/tc_mauve_alert.rb +++ b/test/tc_mauve_alert.rb @@ -109,12 +109,16 @@ EOF ) alert.raise! + logger_pop + assert(alert.raised?) # # This acknowledges an alert for 3 mins. # alert.acknowledge!(person, Time.now + 3.minutes) + logger_pop + assert_equal(person.username, alert.acknowledged_by) assert_equal(Time.now, alert.acknowledged_at) assert_equal(Time.now + 3.minutes, alert.will_unacknowledge_at) @@ -132,6 +136,8 @@ EOF # The alert should unacknowledge itself. # alert.poll + logger_pop + assert(!alert.acknowledged?) end diff --git a/test/tc_mauve_alert_changed.rb b/test/tc_mauve_alert_changed.rb index 3c43a2a..9cae742 100644 --- a/test/tc_mauve_alert_changed.rb +++ b/test/tc_mauve_alert_changed.rb @@ -64,7 +64,7 @@ EOF reminders += 1 end - AlertChanged.all.each{|ac| ac.poll} + AlertChanged.all.each{|ac| ac.poll; logger_pop} end # OK now clear the alert, send one notification and but not an alert_changed. diff --git a/test/tc_mauve_notification.rb b/test/tc_mauve_notification.rb index 018c31a..4243874 100644 --- a/test/tc_mauve_notification.rb +++ b/test/tc_mauve_notification.rb @@ -100,7 +100,7 @@ class TcMauveDuringRunner < Mauve::UnitTest def test_x_in_list_of_y - mdr = Mauve::DuringRunner.new(Time.now) + dr = DuringRunner.new(Time.now) [ [[0,1,3,4], 2, false], [[0,2,4,6], 2, true], @@ -108,14 +108,14 @@ class TcMauveDuringRunner < Mauve::UnitTest [[0..2, 4,5],2, true], [[0,1..3], 2, true], ].each do |y,x,result| - assert_equal(result, mdr.send(:x_in_list_of_y, x,y)) + assert_equal(result, dr.send(:x_in_list_of_y, x,y)) end end def test_hours_in_day t = Time.gm(2010,1,2,3,4,5) # => Sat Jan 02 03:04:05 UTC 2010 - mdr = Mauve::DuringRunner.new(t) + dr = DuringRunner.new(t) [ [[0,1,3,4], true], [[0,2,4,6], false], @@ -126,14 +126,14 @@ class TcMauveDuringRunner < Mauve::UnitTest [[0,1..3], true], [[4..12], false] ].each do |hours, result| - assert_equal(result, mdr.send(:hours_in_day, hours)) + assert_equal(result, dr.send(:hours_in_day, hours)) end end def test_days_in_week t = Time.gm(2010,1,2,3,4,5) # => Sat Jan 02 03:04:05 UTC 2010 - mdr = Mauve::DuringRunner.new(t) + dr = DuringRunner.new(t) [ [[0,1,3,4], false], [[0,2,4,6], true], @@ -144,11 +144,25 @@ class TcMauveDuringRunner < Mauve::UnitTest [[0,1..3], false], [[4..6], true] ].each do |days, result| - assert_equal(result, mdr.send(:days_in_week, days), "#{t.wday} in #{days.join(", ")}") + assert_equal(result, dr.send(:days_in_week, days), "#{t.wday} in #{days.join(", ")}") end end def test_unacknowledged + Server.instance.setup + alert = Alert.new( + :alert_id => "test", + :source => "test", + :subject => "test" + ) + alert.raise! + + Timecop.freeze(Time.now+1.hour) + + dr = DuringRunner.new(Time.now, alert) + + assert(!dr.send(:unacknowledged, 2.hours)) + assert(dr.send(:unacknowledged, 1.hour)) end end @@ -300,4 +314,5 @@ EOF end + end diff --git a/test/tc_mauve_person.rb b/test/tc_mauve_person.rb index 0026db6..c659f00 100644 --- a/test/tc_mauve_person.rb +++ b/test/tc_mauve_person.rb @@ -9,6 +9,8 @@ require 'pp' class TcMauvePerson < Mauve::UnitTest + include Mauve + def setup super setup_database @@ -19,15 +21,83 @@ class TcMauvePerson < Mauve::UnitTest super end - def test_suppressed? - - end - def test_send_alert - - end - - def test_do_send_alert + # + # Allows us to pick up notifications sent. + # + $sent_notifications = [] + + config =<<EOF +person ("test") { + all { $sent_notifications << Time.now ; true } + suppress_notifications_after( 6 => 60.seconds ) +} + +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 + + # + # 6 alerts every 60 seconds. + # + [ [0, true, false], + [5, true, false], + [10, true, false], + [15, true, false], + [20, true, false], + [25, true, true], # 6th alert -- suppress from now on + [30, false, true], + [35, false, true], + [40, false, true], + [60, false, true], # One minute after starting -- should still be suppressed + [65, false, true], + [70, false, true], + [75, false, true], + [80, false, true], + [85, true, false], # One minute after the last alert was sent, start sending again. + [90, true, false] + ].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.suppressed?) + + if notification_sent + assert_equal(1, $sent_notifications.length, "Notification not sent when it should have been.") + # + # 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") + else + assert_equal(0, $sent_notifications.length, "Notification sent when it should not have been.") + end + + logger_pop + end end diff --git a/test/test_mauve.rb b/test/test_mauve.rb index fba47eb..bdce3aa 100644 --- a/test/test_mauve.rb +++ b/test/test_mauve.rb @@ -6,22 +6,23 @@ end require 'pp' require 'test/unit' +require 'th_mauve' %w( +tc_mauve_alert_changed.rb +tc_mauve_alert_group.rb +tc_mauve_alert.rb tc_mauve_configuration_builder.rb tc_mauve_configuration_builders_alert_group.rb tc_mauve_configuration_builders_logger.rb tc_mauve_configuration_builders_notification_method.rb tc_mauve_configuration_builders_person.rb tc_mauve_configuration_builders_server.rb -tc_mauve_source_list.rb -tc_mauve_people_list.rb -tc_mauve_person.rb -tc_mauve_alert.rb tc_mauve_history.rb -tc_mauve_alert_group.rb -tc_mauve_alert_changed.rb tc_mauve_notification.rb +tc_mauve_people_list.rb +tc_mauve_person.rb +tc_mauve_source_list.rb tc_mauve_time.rb ).each do |s| require s diff --git a/test/th_mauve.rb b/test/th_mauve.rb index 76a4933..7972b9d 100644 --- a/test/th_mauve.rb +++ b/test/th_mauve.rb @@ -69,7 +69,7 @@ module Mauve @logger = Log4r::Logger.new 'Mauve' @outputter = Mauve::TestOutputter.new("test") @outputter.formatter = Log4r::PatternFormatter.new( :pattern => "%d %l %m" ) - @outputter.level = Log4r::DEBUG + @outputter.level = Log4r::WARN @logger.outputters << @outputter return @logger end |