aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-08-22 12:01:17 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-08-22 12:01:17 +0100
commitda9ef07cfa2dfd26d1e8efdce5598a7ac7806271 (patch)
treef574227852d475ef772a86366eb8a3c50da1ab1a /test
parent8268305f172376b92957096a2154efe34e275b6a (diff)
* Race condition fixed (fixes #1861).
* Reminders get sent at start of during period (fixes #1821)
Diffstat (limited to 'test')
-rw-r--r--test/tc_mauve_alert_changed.rb10
-rw-r--r--test/tc_mauve_notification.rb79
2 files changed, 70 insertions, 19 deletions
diff --git a/test/tc_mauve_alert_changed.rb b/test/tc_mauve_alert_changed.rb
index 0e57120..3c43a2a 100644
--- a/test/tc_mauve_alert_changed.rb
+++ b/test/tc_mauve_alert_changed.rb
@@ -7,7 +7,7 @@ require 'mauve/configuration_builder'
require 'mauve/configuration_builders'
require 'th_mauve'
-class TcMauveAlertChanged < Mauve::UnitTest
+class TcMauveAlertChanged < Mauve::UnitTest
include Mauve
def setup
@@ -51,13 +51,13 @@ EOF
notifications = 1
mins = 0
- 121.times do
+ 11.times do
mins += 1
assert_equal(notifications, Server.instance.notification_buffer.length)
assert_equal(reminders, AlertChanged.count)
- Timecop.freeze(Time.now+1.minutes)
+ Timecop.freeze(Time.now+1.minute)
if mins % 5 == 0
notifications += 1
@@ -67,10 +67,10 @@ EOF
AlertChanged.all.each{|ac| ac.poll}
end
- # OK now clear the alert, send one notification and set an alert_changed.
+ # OK now clear the alert, send one notification and but not an alert_changed.
alert.clear!
notifications += 1
- reminders += 1
+
assert_equal(notifications, Server.instance.notification_buffer.length)
assert_equal(reminders, AlertChanged.count)
diff --git a/test/tc_mauve_notification.rb b/test/tc_mauve_notification.rb
index 167d069..018c31a 100644
--- a/test/tc_mauve_notification.rb
+++ b/test/tc_mauve_notification.rb
@@ -195,7 +195,7 @@ alert_group("default") {
every 10.minutes
}
- notify("test1") {
+ notify("testers") {
every 15.minutes
}
@@ -222,30 +222,81 @@ EOF
alert.raise!
assert_equal(1, Alert.count, "Wrong number of alerts saved")
+
+ #
+ # Also make sure that only 2 notifications has been sent..
+ #
+ assert_equal(2, Server.instance.notification_buffer.size, "Wrong number of notifications sent")
#
# Although there are four clauses above for notifications, test1 should be
# alerted in 10 minutes time, and the 15 minutes clause is ignored, since
# 10 minutes is sooner.
#
- assert_equal(3, AlertChanged.count, "Wrong number of reminders inserted")
+ assert_equal(1, AlertChanged.count, "Wrong number of reminders inserted")
+
+ a = AlertChanged.first
+ assert_equal("urgent", a.level, "Level is wrong for #{a.person}")
+ assert_equal("raised", a.update_type, "Update type is wrong for #{a.person}")
+ assert_equal(Time.now + 10.minutes, a.remind_at,"reminder time is wrong for #{a.person}")
#
- # Also make sure that only 1 notification has been sent..
+ # OK now roll the clock forward 10 minutes
+ # TODO
+
+ end
+
+
+ #
+ # Makes sure a reminder is set at the start of the notify clause.
+ #
+ def test_reminder_is_set_at_start_of_during
+
+ config=<<EOF
+person ("test1") {
+ all { true }
+}
+
+person ("test2") {
+ all { true }
+}
+
+alert_group("default") {
+ level URGENT
+ notify("test1") {
+ every 10.minutes
+ }
+
+ notify("test2") {
+ every 10.minutes
+ during { hours_in_day 8..10 }
+ }
+
+}
+EOF
+
+ #
+ # Wind forward until 7.55am
#
- assert_equal(1, Server.instance.notification_buffer.size, "Wrong number of notifications sent")
+ Timecop.freeze(Time.now + 7.hours + 55.minutes)
- reminder_times = {
- "test1" => t + 10.minutes,
- "test2" => t + 1.hour,
- "test3" => t + 2.hours
- }
+ Configuration.current = ConfigurationBuilder.parse(config)
+ Server.instance.setup
+ alert = Alert.new(
+ :alert_id => "test",
+ :source => "test",
+ :subject => "test"
+ )
+ alert.raise!
- AlertChanged.all.each do |a|
- assert_equal("urgent", a.level, "Level is wrong for #{a.person}")
- assert_equal("raised", a.update_type, "Update type is wrong for #{a.person}")
- assert_equal(reminder_times[a.person], a.remind_at,"reminder time is wrong for #{a.person}")
- end
+ assert_equal(1, Alert.count, "Wrong number of alerts saved")
+
+ assert_equal(1, AlertChanged.count, "Wrong number of reminders inserted")
+
+ a = AlertChanged.first
+ assert_equal("urgent", a.level, "Level is wrong for #{a.person}")
+ assert_equal("raised", a.update_type, "Update type is wrong for #{a.person}")
+ assert_equal(Time.now + 5.minutes, a.remind_at,"reminder time is wrong for #{a.person}")
end