aboutsummaryrefslogtreecommitdiff
path: root/test/tc_mauve_alert_changed.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/tc_mauve_alert_changed.rb')
-rw-r--r--test/tc_mauve_alert_changed.rb56
1 files changed, 49 insertions, 7 deletions
diff --git a/test/tc_mauve_alert_changed.rb b/test/tc_mauve_alert_changed.rb
index 9cae742..ba31dd9 100644
--- a/test/tc_mauve_alert_changed.rb
+++ b/test/tc_mauve_alert_changed.rb
@@ -1,11 +1,11 @@
$:.unshift "../lib"
+require 'th_mauve'
require 'mauve/alert'
require 'mauve/alert_changed'
require 'mauve/configuration'
require 'mauve/configuration_builder'
require 'mauve/configuration_builders'
-require 'th_mauve'
class TcMauveAlertChanged < Mauve::UnitTest
include Mauve
@@ -23,10 +23,6 @@ class TcMauveAlertChanged < Mauve::UnitTest
def test_reminder
config=<<EOF
-server {
- database "sqlite::memory:"
-}
-
person("test_person") {
all { true }
}
@@ -40,11 +36,11 @@ alert_group("test_group") {
}
EOF
- Mauve::Configuration.current = Mauve::ConfigurationBuilder.parse(config)
+ Configuration.current = ConfigurationBuilder.parse(config)
Server.instance.setup
- alert = Mauve::Alert.new(:source => "test", :alert_id => "test_alert", :summary => "test alert")
+ alert = Alert.new(:source => "test", :alert_id => "test_alert", :summary => "test alert")
alert.raise!
reminders = 1
@@ -84,6 +80,52 @@ EOF
end
+ def test_only_send_one_alert_on_unacknowledge
+ config=<<EOF
+person("test_person") {
+ all { true }
+}
+
+alert_group("test_group") {
+
+ notify("test_person") {
+ every 5.minutes
+ }
+
+}
+EOF
+
+ Configuration.current = ConfigurationBuilder.parse(config)
+
+ Server.instance.setup
+
+ alert = Alert.new(:source => "test", :alert_id => "test_alert", :summary => "test alert")
+ alert.raise!
+ assert_equal(1,Server.instance.notification_buffer.length, "Wrong no of notifications sent after raise.")
+ assert_equal(1,AlertChanged.count, "Wrong no of AlertChangeds created after raise.")
+
+ alert.acknowledge!(Configuration.current.people["test_person"], Time.now + 10.minutes)
+ assert_equal(2,Server.instance.notification_buffer.length, "Wrong no of notifications sent after acknowledge.")
+ assert_equal(2,AlertChanged.count, "Wrong no of AlertChangeds created after acknowledge.")
+
+ Timecop.freeze(Time.now + 10.minutes)
+ AlertChanged.all.each{|ac| ac.poll}
+ assert_equal(2,Server.instance.notification_buffer.length, "Extra notifications sent when alertchangeds are polled.")
+
+ #
+ # OK if we poll the alert now it should be re-raised.
+ #
+ alert.poll
+ assert(!alert.acknowledged?,"Alert not unacknowledged")
+ assert(alert.raised?,"Alert not raised following unacknowledgment")
+ assert_equal(3,Server.instance.notification_buffer.length, "No re-raise notification sent.")
+ #
+ # If we poll the AlertChangeds again, no further notification should be sent.
+ #
+ AlertChanged.all.each{|ac| ac.poll}
+ assert_equal(3,Server.instance.notification_buffer.length, "Extra notifications sent when alertchangeds are polled.")
+
+ end
end