blob: 9cae7429912d05ada7e1f295c0d3715a19f8e8cb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
$:.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
11.times do
mins += 1
assert_equal(notifications, Server.instance.notification_buffer.length)
assert_equal(reminders, AlertChanged.count)
Timecop.freeze(Time.now+1.minute)
if mins % 5 == 0
notifications += 1
reminders += 1
end
AlertChanged.all.each{|ac| ac.poll; logger_pop}
end
# OK now clear the alert, send one notification and but not an alert_changed.
alert.clear!
notifications += 1
assert_equal(notifications, Server.instance.notification_buffer.length)
assert_equal(reminders, AlertChanged.count)
Timecop.freeze(Time.now + 10.minutes)
AlertChanged.all.each{|ac| ac.poll}
#
# Send NO MORE notifications.
#
assert_equal(notifications, Server.instance.notification_buffer.length)
assert_equal(reminders, AlertChanged.count)
end
end
|