aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-04-24 10:56:31 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-04-24 10:56:31 +0100
commit5fff12fc11cb8b02a44fd40ed78fa9d196f269d7 (patch)
tree18e65b389115390f270eef893d641f73165b798f /test
parentb0555e8e3012b5ccc67ab9884dd8bb65e53bb8fd (diff)
Updated people_list and notification tests.
Diffstat (limited to 'test')
-rw-r--r--test/tc_mauve_notification.rb37
-rw-r--r--test/tc_mauve_people_list.rb120
2 files changed, 151 insertions, 6 deletions
diff --git a/test/tc_mauve_notification.rb b/test/tc_mauve_notification.rb
index 16b6489..a447207 100644
--- a/test/tc_mauve_notification.rb
+++ b/test/tc_mauve_notification.rb
@@ -420,7 +420,7 @@ person ("test1") {
all { email }
notify {
every 300
- during { !working_hours? }
+ during { hours_in_day(0) }
}
}
@@ -429,7 +429,14 @@ person ("test2") {
all { email }
notify {
every 300
- during { working_hours? }
+ during { hours_in_day(1) }
+ }
+}
+
+people_list("testers", %w(test1 test2)) {
+ notify {
+ every 150
+ during { hours_in_day(2) }
}
}
@@ -437,6 +444,7 @@ alert_group("test") {
level URGENT
notify("test1")
notify("test2")
+ notify("testers")
}
EOF
@@ -455,6 +463,7 @@ EOF
#
# This should only alert test1
#
+ assert_equal(0, Time.now.hour)
alert.raise!
assert_equal(1, notification_buffer.size, "Wrong number of notifications sent")
assert_equal("test1@example.com", notification_buffer.pop[2])
@@ -464,10 +473,11 @@ EOF
assert_equal("test1@example.com", notification_buffer.pop[2])
#
- # Wind forward to 9am (working hours)
+ # Wind forward to 1am when test2 should get alerted
#
- Timecop.freeze(Time.now+9.hours)
- assert(Time.now.working_hours?)
+ Timecop.freeze(Time.now+1.hours)
+
+ assert_equal(1, Time.now.hour)
alert.raise!
assert_equal(1, notification_buffer.size, "Wrong number of notifications sent")
assert_equal("test2@example.com", notification_buffer.pop[2])
@@ -475,7 +485,22 @@ EOF
alert.clear!
assert_equal(1, notification_buffer.size, "Wrong number of notifications sent")
assert_equal("test2@example.com", notification_buffer.pop[2])
-
+
+ #
+ # Wind forward to 2am when the testers group should get alerted
+ #
+ Timecop.freeze(Time.now+1.hours)
+
+ assert_equal(2, Time.now.hour)
+ alert.raise!
+ assert_equal(2, notification_buffer.size, "Wrong number of notifications sent")
+ assert_equal("test2@example.com", notification_buffer.pop[2])
+ assert_equal("test1@example.com", notification_buffer.pop[2])
+
+ alert.clear!
+ assert_equal(2, notification_buffer.size, "Wrong number of notifications sent")
+ assert_equal("test2@example.com", notification_buffer.pop[2])
+ assert_equal("test1@example.com", notification_buffer.pop[2])
end
diff --git a/test/tc_mauve_people_list.rb b/test/tc_mauve_people_list.rb
index e69de29..2d5da6d 100644
--- a/test/tc_mauve_people_list.rb
+++ b/test/tc_mauve_people_list.rb
@@ -0,0 +1,120 @@
+$:.unshift "../lib"
+
+require 'th_mauve'
+require 'mauve/people_list'
+require 'mauve/configuration'
+require 'mauve/configuration_builder'
+require 'mauve/configuration_builders'
+require 'pp'
+
+class TcMauvePeopleList < Mauve::UnitTest
+
+ include Mauve
+
+ def setup
+ super
+ setup_database
+ end
+
+ def teardown
+ teardown_database
+ super
+ end
+
+ def test_send_alert
+ #
+ # Allows us to pick up notifications sent.
+ #
+ $sent_notifications = []
+
+ config =<<EOF
+notification_method("email") {
+ debug!
+ disable_normal_delivery!
+ deliver_to_queue []
+}
+
+person ("test1") {
+ email "test@example.com"
+ all { email }
+ suppress_notifications_after( 6 => 60.seconds )
+}
+
+person ("test2") {
+ email "test@example.com"
+ all { email }
+ suppress_notifications_after( 1 => 1.minute )
+}
+
+people_list "testers", %w(test1 test2)
+
+alert_group("default") {
+ level URGENT
+
+ notify("testers") {
+ every 10.seconds
+ }
+}
+EOF
+ Configuration.current = ConfigurationBuilder.parse(config)
+ notification_buffer = Configuration.current.notification_methods["email"].deliver_to_queue
+
+ Server.instance.setup
+ people_list = Configuration.current.people_lists["testers"]
+
+ alert = Alert.new(
+ :alert_id => "test",
+ :source => "test",
+ :subject => "test"
+ )
+ alert.raise!
+# assert_equal(false, .suppressed?, "Person suppressed before we even begin!")
+
+ start_time = Time.now
+
+ #
+ # 6 alerts every 60 seconds.
+ #
+ [ [0, true, true],
+ [5, true, false],
+ [10, true, false],
+ [15, true, false],
+ [20, true, false],
+ [25, true, false], # 6th alert -- suppress from now on
+ [30, false, false],
+ [35, false, false],
+ [40, false, false],
+ [60, false, true], # One minute after starting -- should still be suppressed
+ [65, false, false],
+ [70, false, false],
+ [75, false, false],
+ [80, false, false],
+ [85, true, false], # One minute after the last alert was sent, start sending again.
+ [90, true, false]
+ ].each do |offset, test1sent, test2sent|
+ #
+ # Advance in to the future!
+ #
+ Timecop.freeze(start_time + offset)
+
+ people_list.people.each{|person| person.send_alert(alert.level, alert) }
+
+
+ if test1sent or test2sent
+ n_notifications = (test2sent ? 1 : 0) + (test1sent ? 1 : 0)
+ assert_equal(n_notifications, notification_buffer.length, "Notification not sent when it should have been at #{Time.now}.")
+ #
+ # Pop the notification off the buffer.
+ #
+ n_notifications.times{ notification_buffer.pop }
+# assert_equal(Time.now, person.notification_thresholds[60][-1], "Notification thresholds not updated at #{Time.now}.")
+ else
+ assert_equal(0, notification_buffer.length, "Notification sent when it should not have been at #{Time.now}.")
+ end
+
+
+ logger_pop
+ end
+
+ end
+end