aboutsummaryrefslogtreecommitdiff
path: root/test/tc_mauve_alert_changed.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-08-17 11:08:07 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-08-17 11:08:07 +0100
commit8c8e5ae926e0009743fe92dccb588783640a6022 (patch)
treee23eea583beac0caf5fb3e45a33b4d2ac7796abf /test/tc_mauve_alert_changed.rb
parent79dcf16ec6d229d6c31e055ed8e6a98327526a3a (diff)
* Reminder notifications now take the same path to notify as initial alerts
* Threading tidied -- processor will not do anything unless the timer has frozen * Person#send_alert now tidied and merged with alert_changed * POP3 server only shows alerts relevant to the user * Server now defaults to using an in-memory SQLite database (good for testing) * Server initializes a blank mauve config. * Tests tidied up
Diffstat (limited to 'test/tc_mauve_alert_changed.rb')
-rw-r--r--test/tc_mauve_alert_changed.rb76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/tc_mauve_alert_changed.rb b/test/tc_mauve_alert_changed.rb
new file mode 100644
index 0000000..52f1f25
--- /dev/null
+++ b/test/tc_mauve_alert_changed.rb
@@ -0,0 +1,76 @@
+$:.unshift "../lib"
+
+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
+
+ def setup
+ super
+ setup_database
+ end
+
+ def teardown
+ teardown_database
+ super
+ end
+
+ def test_reminder
+
+ config=<<EOF
+server {
+ database "sqlite::memory:"
+}
+
+person("test_person") {
+ all { true }
+}
+
+alert_group("test_group") {
+
+ notify("test_person") {
+ every 5.minutes
+ }
+
+}
+EOF
+
+ Mauve::Configuration.current = Mauve::ConfigurationBuilder.parse(config)
+
+ Server.instance.setup
+
+ alert = Mauve::Alert.new(:source => "test", :alert_id => "test_alert", :summary => "test alert")
+ alert.raise!
+
+ reminders = 1
+ notifications = 1
+
+ mins = 0
+ 121.times do
+ mins += 1
+
+ assert_equal(notifications, Server.instance.notification_buffer.length)
+ assert_equal(reminders, AlertChanged.count)
+
+ Timecop.freeze(Time.now+1.minutes)
+
+ if mins % 5 == 0
+ notifications += 1
+ reminders += 1
+ end
+
+ AlertChanged.all.each{|ac| ac.poll}
+ end
+
+ end
+
+
+end
+
+
+