resurrected_god 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Announce.txt +135 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.md +33 -0
- data/Rakefile +129 -0
- data/bin/god +134 -0
- data/doc/god.asciidoc +1592 -0
- data/doc/intro.asciidoc +20 -0
- data/ext/god/.gitignore +5 -0
- data/ext/god/extconf.rb +56 -0
- data/ext/god/kqueue_handler.c +133 -0
- data/ext/god/netlink_handler.c +182 -0
- data/lib/god/behavior.rb +52 -0
- data/lib/god/behaviors/clean_pid_file.rb +21 -0
- data/lib/god/behaviors/clean_unix_socket.rb +21 -0
- data/lib/god/behaviors/notify_when_flapping.rb +51 -0
- data/lib/god/cli/command.rb +268 -0
- data/lib/god/cli/run.rb +170 -0
- data/lib/god/cli/version.rb +23 -0
- data/lib/god/compat19.rb +33 -0
- data/lib/god/condition.rb +96 -0
- data/lib/god/conditions/always.rb +36 -0
- data/lib/god/conditions/complex.rb +86 -0
- data/lib/god/conditions/cpu_usage.rb +80 -0
- data/lib/god/conditions/degrading_lambda.rb +52 -0
- data/lib/god/conditions/disk_usage.rb +32 -0
- data/lib/god/conditions/file_mtime.rb +28 -0
- data/lib/god/conditions/file_touched.rb +44 -0
- data/lib/god/conditions/flapping.rb +128 -0
- data/lib/god/conditions/http_response_code.rb +184 -0
- data/lib/god/conditions/lambda.rb +25 -0
- data/lib/god/conditions/memory_usage.rb +82 -0
- data/lib/god/conditions/process_exits.rb +66 -0
- data/lib/god/conditions/process_running.rb +63 -0
- data/lib/god/conditions/socket_responding.rb +142 -0
- data/lib/god/conditions/tries.rb +44 -0
- data/lib/god/configurable.rb +57 -0
- data/lib/god/contact.rb +114 -0
- data/lib/god/contacts/airbrake.rb +44 -0
- data/lib/god/contacts/campfire.rb +121 -0
- data/lib/god/contacts/email.rb +130 -0
- data/lib/god/contacts/hipchat.rb +117 -0
- data/lib/god/contacts/jabber.rb +75 -0
- data/lib/god/contacts/prowl.rb +57 -0
- data/lib/god/contacts/scout.rb +55 -0
- data/lib/god/contacts/sensu.rb +59 -0
- data/lib/god/contacts/slack.rb +98 -0
- data/lib/god/contacts/statsd.rb +46 -0
- data/lib/god/contacts/twitter.rb +51 -0
- data/lib/god/contacts/webhook.rb +74 -0
- data/lib/god/driver.rb +238 -0
- data/lib/god/errors.rb +24 -0
- data/lib/god/event_handler.rb +112 -0
- data/lib/god/event_handlers/dummy_handler.rb +13 -0
- data/lib/god/event_handlers/kqueue_handler.rb +17 -0
- data/lib/god/event_handlers/netlink_handler.rb +13 -0
- data/lib/god/logger.rb +109 -0
- data/lib/god/metric.rb +87 -0
- data/lib/god/process.rb +381 -0
- data/lib/god/registry.rb +32 -0
- data/lib/god/simple_logger.rb +59 -0
- data/lib/god/socket.rb +113 -0
- data/lib/god/sugar.rb +62 -0
- data/lib/god/sys_logger.rb +45 -0
- data/lib/god/system/portable_poller.rb +42 -0
- data/lib/god/system/process.rb +50 -0
- data/lib/god/system/slash_proc_poller.rb +92 -0
- data/lib/god/task.rb +552 -0
- data/lib/god/timeline.rb +25 -0
- data/lib/god/trigger.rb +43 -0
- data/lib/god/version.rb +4 -0
- data/lib/god/watch.rb +340 -0
- data/lib/god.rb +777 -0
- data/test/configs/child_events/child_events.god +44 -0
- data/test/configs/child_events/simple_server.rb +3 -0
- data/test/configs/child_polls/child_polls.god +37 -0
- data/test/configs/child_polls/simple_server.rb +12 -0
- data/test/configs/complex/complex.god +59 -0
- data/test/configs/complex/simple_server.rb +3 -0
- data/test/configs/contact/contact.god +118 -0
- data/test/configs/contact/simple_server.rb +3 -0
- data/test/configs/daemon_events/daemon_events.god +37 -0
- data/test/configs/daemon_events/simple_server.rb +8 -0
- data/test/configs/daemon_events/simple_server_stop.rb +11 -0
- data/test/configs/daemon_polls/daemon_polls.god +17 -0
- data/test/configs/daemon_polls/simple_server.rb +6 -0
- data/test/configs/degrading_lambda/degrading_lambda.god +31 -0
- data/test/configs/degrading_lambda/tcp_server.rb +15 -0
- data/test/configs/keepalive/keepalive.god +9 -0
- data/test/configs/keepalive/keepalive.rb +12 -0
- data/test/configs/lifecycle/lifecycle.god +25 -0
- data/test/configs/matias/matias.god +50 -0
- data/test/configs/real.rb +59 -0
- data/test/configs/running_load/running_load.god +16 -0
- data/test/configs/stop_options/simple_server.rb +12 -0
- data/test/configs/stop_options/stop_options.god +39 -0
- data/test/configs/stress/simple_server.rb +3 -0
- data/test/configs/stress/stress.god +15 -0
- data/test/configs/task/logs/.placeholder +0 -0
- data/test/configs/task/task.god +26 -0
- data/test/configs/test.rb +61 -0
- data/test/configs/usr1_trapper.rb +10 -0
- data/test/helper.rb +172 -0
- data/test/suite.rb +6 -0
- data/test/test_airbrake.rb +14 -0
- data/test/test_behavior.rb +18 -0
- data/test/test_campfire.rb +22 -0
- data/test/test_condition.rb +52 -0
- data/test/test_conditions_disk_usage.rb +50 -0
- data/test/test_conditions_http_response_code.rb +109 -0
- data/test/test_conditions_process_running.rb +40 -0
- data/test/test_conditions_socket_responding.rb +176 -0
- data/test/test_conditions_tries.rb +67 -0
- data/test/test_contact.rb +109 -0
- data/test/test_driver.rb +26 -0
- data/test/test_email.rb +34 -0
- data/test/test_event_handler.rb +82 -0
- data/test/test_god.rb +710 -0
- data/test/test_god_system.rb +201 -0
- data/test/test_handlers_kqueue_handler.rb +16 -0
- data/test/test_hipchat.rb +23 -0
- data/test/test_jabber.rb +29 -0
- data/test/test_logger.rb +55 -0
- data/test/test_metric.rb +74 -0
- data/test/test_process.rb +263 -0
- data/test/test_prowl.rb +15 -0
- data/test/test_registry.rb +15 -0
- data/test/test_sensu.rb +11 -0
- data/test/test_slack.rb +57 -0
- data/test/test_socket.rb +34 -0
- data/test/test_statsd.rb +22 -0
- data/test/test_sugar.rb +42 -0
- data/test/test_system_portable_poller.rb +17 -0
- data/test/test_system_process.rb +30 -0
- data/test/test_task.rb +246 -0
- data/test/test_timeline.rb +37 -0
- data/test/test_trigger.rb +63 -0
- data/test/test_watch.rb +286 -0
- data/test/test_webhook.rb +22 -0
- metadata +476 -0
@@ -0,0 +1,176 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestConditionsSocketResponding < Minitest::Test
|
4
|
+
# valid?
|
5
|
+
|
6
|
+
def test_valid_should_return_false_if_no_options_set
|
7
|
+
c = Conditions::SocketResponding.new
|
8
|
+
c.watch = stub(:name => 'foo')
|
9
|
+
assert_equal false, c.valid?
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_valid_should_return_true_if_required_options_set_for_default
|
14
|
+
c = Conditions::SocketResponding.new
|
15
|
+
c.port = 443
|
16
|
+
assert_equal true, c.valid?
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_valid_should_return_true_if_required_options_set_for_tcp
|
20
|
+
c = Conditions::SocketResponding.new
|
21
|
+
c.family = 'tcp'
|
22
|
+
c.port = 443
|
23
|
+
assert_equal true, c.valid?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_valid_should_return_true_if_required_options_set_for_unix
|
27
|
+
c = Conditions::SocketResponding.new
|
28
|
+
c.path = 'some-path'
|
29
|
+
c.family = 'unix'
|
30
|
+
assert_equal true, c.valid?
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_valid_should_return_true_if_family_is_tcp
|
34
|
+
c = Conditions::SocketResponding.new
|
35
|
+
c.port = 443
|
36
|
+
c.family = 'tcp'
|
37
|
+
assert_equal true, c.valid?
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_valid_should_return_true_if_family_is_unix
|
41
|
+
c = Conditions::SocketResponding.new
|
42
|
+
c.path = 'some-path'
|
43
|
+
c.family = 'unix'
|
44
|
+
c.watch = stub(:name => 'foo')
|
45
|
+
assert_equal true, c.valid?
|
46
|
+
end
|
47
|
+
|
48
|
+
# socket method
|
49
|
+
def test_socket_should_return_127_0_0_1_for_default_addr
|
50
|
+
c = Conditions::SocketResponding.new
|
51
|
+
c.socket = 'tcp:443'
|
52
|
+
assert_equal c.addr, '127.0.0.1'
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_socket_should_set_properties_for_tcp
|
56
|
+
c = Conditions::SocketResponding.new
|
57
|
+
c.socket = 'tcp:127.0.0.1:443'
|
58
|
+
assert_equal c.family, 'tcp'
|
59
|
+
assert_equal c.addr, '127.0.0.1'
|
60
|
+
assert_equal c.port, 443
|
61
|
+
assert_equal c.responding, false
|
62
|
+
# path should not be set for tcp sockets
|
63
|
+
assert_equal c.path, nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_socket_should_set_properties_for_unix
|
67
|
+
c = Conditions::SocketResponding.new
|
68
|
+
c.socket = 'unix:/tmp/process.sock'
|
69
|
+
assert_equal c.family, 'unix'
|
70
|
+
assert_equal c.path, '/tmp/process.sock'
|
71
|
+
assert_equal c.responding, false
|
72
|
+
# path should not be set for unix domain sockets
|
73
|
+
assert_equal c.port, 0
|
74
|
+
end
|
75
|
+
|
76
|
+
# test : responding = false
|
77
|
+
|
78
|
+
def test_test_tcp_should_return_false_if_socket_is_listening
|
79
|
+
c = Conditions::SocketResponding.new
|
80
|
+
c.prepare
|
81
|
+
|
82
|
+
TCPSocket.expects(:new).returns(0)
|
83
|
+
assert_equal false, c.test
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_test_tcp_should_return_true_if_no_socket_is_listening
|
87
|
+
c = Conditions::SocketResponding.new
|
88
|
+
c.prepare
|
89
|
+
|
90
|
+
TCPSocket.expects(:new).returns(nil)
|
91
|
+
assert_equal true, c.test
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_test_unix_should_return_false_if_socket_is_listening
|
95
|
+
c = Conditions::SocketResponding.new
|
96
|
+
c.socket = 'unix:/some/path'
|
97
|
+
|
98
|
+
c.prepare
|
99
|
+
UNIXSocket.expects(:new).returns(0)
|
100
|
+
assert_equal false, c.test
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_test_unix_should_return_true_if_no_socket_is_listening
|
104
|
+
|
105
|
+
c = Conditions::SocketResponding.new
|
106
|
+
c.socket = 'unix:/some/path'
|
107
|
+
c.prepare
|
108
|
+
|
109
|
+
UNIXSocket.expects(:new).returns(nil)
|
110
|
+
assert_equal true, c.test
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_test_unix_should_return_true_if_socket_is_listening_2_times
|
114
|
+
|
115
|
+
c = Conditions::SocketResponding.new
|
116
|
+
c.socket = 'unix:/some/path'
|
117
|
+
c.times = [2, 2]
|
118
|
+
c.prepare
|
119
|
+
|
120
|
+
UNIXSocket.expects(:new).returns(nil).times(2)
|
121
|
+
assert_equal false, c.test
|
122
|
+
assert_equal true, c.test
|
123
|
+
end
|
124
|
+
|
125
|
+
# test : responding = true
|
126
|
+
|
127
|
+
def test_test_tcp_should_return_true_if_socket_is_listening_with_responding_true
|
128
|
+
c = Conditions::SocketResponding.new
|
129
|
+
c.responding = true
|
130
|
+
c.prepare
|
131
|
+
|
132
|
+
TCPSocket.expects(:new).returns(0)
|
133
|
+
assert_equal true, c.test
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_test_tcp_should_return_false_if_no_socket_is_listening_with_responding_true
|
137
|
+
c = Conditions::SocketResponding.new
|
138
|
+
c.responding = true
|
139
|
+
c.prepare
|
140
|
+
|
141
|
+
TCPSocket.expects(:new).returns(nil)
|
142
|
+
assert_equal false, c.test
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_test_unix_should_return_true_if_socket_is_listening_with_responding_true
|
146
|
+
c = Conditions::SocketResponding.new
|
147
|
+
c.responding = true
|
148
|
+
c.socket = 'unix:/some/path'
|
149
|
+
|
150
|
+
c.prepare
|
151
|
+
UNIXSocket.expects(:new).returns(0)
|
152
|
+
assert_equal true, c.test
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_test_unix_should_return_false_if_no_socket_is_listening_with_responding_true
|
156
|
+
c = Conditions::SocketResponding.new
|
157
|
+
c.socket = 'unix:/some/path'
|
158
|
+
c.responding = true
|
159
|
+
c.prepare
|
160
|
+
|
161
|
+
UNIXSocket.expects(:new).returns(nil)
|
162
|
+
assert_equal false, c.test
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_test_unix_should_return_false_if_socket_is_listening_2_times_with_responding_true
|
166
|
+
c = Conditions::SocketResponding.new
|
167
|
+
c.socket = 'unix:/some/path'
|
168
|
+
c.responding = true
|
169
|
+
c.times = [2, 2]
|
170
|
+
c.prepare
|
171
|
+
|
172
|
+
UNIXSocket.expects(:new).returns(nil).times(2)
|
173
|
+
assert_equal false, c.test
|
174
|
+
assert_equal false, c.test
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestConditionsTries < Minitest::Test
|
4
|
+
# valid?
|
5
|
+
|
6
|
+
def test_valid_should_return_false_if_times_not_set
|
7
|
+
c = Conditions::Tries.new
|
8
|
+
c.watch = stub(:name => 'foo')
|
9
|
+
assert !c.valid?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
class TestConditionsTries < Minitest::Test
|
15
|
+
def setup
|
16
|
+
@c = Conditions::Tries.new
|
17
|
+
@c.times = 3
|
18
|
+
@c.prepare
|
19
|
+
end
|
20
|
+
|
21
|
+
# prepare
|
22
|
+
|
23
|
+
def test_prepare_should_create_timeline
|
24
|
+
assert_equal 3, @c.instance_variable_get(:@timeline).instance_variable_get(:@max_size)
|
25
|
+
end
|
26
|
+
|
27
|
+
# test
|
28
|
+
|
29
|
+
def test_test_should_return_true_if_called_three_times_within_one_second
|
30
|
+
assert !@c.test
|
31
|
+
assert !@c.test
|
32
|
+
assert @c.test
|
33
|
+
end
|
34
|
+
|
35
|
+
# reset
|
36
|
+
|
37
|
+
def test_test_should_return_false_on_fourth_call_if_called_three_times_within_one_second
|
38
|
+
3.times { @c.test }
|
39
|
+
@c.reset
|
40
|
+
assert !@c.test
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
class TestConditionsTriesWithin < Minitest::Test
|
46
|
+
def setup
|
47
|
+
@c = Conditions::Tries.new
|
48
|
+
@c.times = 3
|
49
|
+
@c.within = 1.seconds
|
50
|
+
@c.prepare
|
51
|
+
end
|
52
|
+
|
53
|
+
# test
|
54
|
+
|
55
|
+
def test_test_should_return_true_if_called_three_times_within_one_second
|
56
|
+
assert !@c.test
|
57
|
+
assert !@c.test
|
58
|
+
assert @c.test
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_test_should_return_false_if_called_three_times_within_two_seconds
|
62
|
+
assert !@c.test
|
63
|
+
assert !@c.test
|
64
|
+
assert sleep(1.1)
|
65
|
+
assert !@c.test
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestContact < Minitest::Test
|
4
|
+
def test_exists
|
5
|
+
God::Contact
|
6
|
+
end
|
7
|
+
|
8
|
+
# generate
|
9
|
+
|
10
|
+
def test_generate_should_raise_on_invalid_kind
|
11
|
+
assert_raises(NoSuchContactError) do
|
12
|
+
Contact.generate(:invalid)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_generate_should_abort_on_invalid_contact
|
17
|
+
assert_abort do
|
18
|
+
Contact.generate(:invalid_contact)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# normalize
|
23
|
+
|
24
|
+
def test_normalize_should_accept_a_string
|
25
|
+
input = 'tom'
|
26
|
+
output = {:contacts => ['tom']}
|
27
|
+
assert_equal(output, Contact.normalize(input))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_normalize_should_accept_an_array_of_strings
|
31
|
+
input = ['tom', 'kevin']
|
32
|
+
output = {:contacts => ['tom', 'kevin']}
|
33
|
+
assert_equal(output, Contact.normalize(input))
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_normalize_should_accept_a_hash_with_contacts_string
|
37
|
+
input = {:contacts => 'tom'}
|
38
|
+
output = {:contacts => ['tom']}
|
39
|
+
assert_equal(output, Contact.normalize(input))
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_normalize_should_accept_a_hash_with_contacts_array_of_strings
|
43
|
+
input = {:contacts => ['tom', 'kevin']}
|
44
|
+
output = {:contacts => ['tom', 'kevin']}
|
45
|
+
assert_equal(output, Contact.normalize(input))
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_normalize_should_stringify_priority
|
49
|
+
input = {:contacts => 'tom', :priority => 1}
|
50
|
+
output = {:contacts => ['tom'], :priority => '1'}
|
51
|
+
assert_equal(output, Contact.normalize(input))
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_normalize_should_stringify_category
|
55
|
+
input = {:contacts => 'tom', :category => :product}
|
56
|
+
output = {:contacts => ['tom'], :category => 'product'}
|
57
|
+
assert_equal(output, Contact.normalize(input))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_normalize_should_raise_on_non_string_array_hash
|
61
|
+
input = 1
|
62
|
+
assert_raises ArgumentError do
|
63
|
+
Contact.normalize(input)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_normalize_should_raise_on_non_string_array_contacts_key
|
68
|
+
input = {:contacts => 1}
|
69
|
+
assert_raises ArgumentError do
|
70
|
+
Contact.normalize(input)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_normalize_should_raise_on_non_string_containing_array
|
75
|
+
input = [1]
|
76
|
+
assert_raises ArgumentError do
|
77
|
+
Contact.normalize(input)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_normalize_should_raise_on_non_string_containing_array_contacts_key
|
82
|
+
input = {:contacts => [1]}
|
83
|
+
assert_raises ArgumentError do
|
84
|
+
Contact.normalize(input)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_normalize_should_raise_on_absent_contacts_key
|
89
|
+
input = {}
|
90
|
+
assert_raises ArgumentError do
|
91
|
+
Contact.normalize(input)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_normalize_should_raise_on_extra_keys
|
96
|
+
input = {:contacts => ['tom'], :priority => 1, :category => 'product', :extra => 'foo'}
|
97
|
+
assert_raises ArgumentError do
|
98
|
+
Contact.normalize(input)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# notify
|
103
|
+
|
104
|
+
def test_notify_should_be_abstract
|
105
|
+
assert_raises(AbstractMethodNotOverriddenError) do
|
106
|
+
Contact.new.notify(:a, :b, :c, :d, :e)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/test/test_driver.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestDriver < Minitest::Test
|
4
|
+
def setup
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_push_pop_wait
|
9
|
+
|
10
|
+
eq = God::DriverEventQueue.new
|
11
|
+
cond = eq.instance_variable_get(:@resource)
|
12
|
+
cond.expects(:wait).times(1)
|
13
|
+
|
14
|
+
eq.push(God::TimedEvent.new(0))
|
15
|
+
eq.push(God::TimedEvent.new(0.1))
|
16
|
+
t = Thread.new do
|
17
|
+
# This pop will see an event immediately available, so no wait.
|
18
|
+
assert_equal TimedEvent, eq.pop.class
|
19
|
+
|
20
|
+
# This pop will happen before the next event is due, so wait.
|
21
|
+
assert_equal TimedEvent, eq.pop.class
|
22
|
+
end
|
23
|
+
|
24
|
+
t.join
|
25
|
+
end
|
26
|
+
end
|
data/test/test_email.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestEmail < Minitest::Test
|
4
|
+
def setup
|
5
|
+
God::Contacts::Email.to_email = 'dev@example.com'
|
6
|
+
God::Contacts::Email.from_email = 'god@example.com'
|
7
|
+
@email = God::Contacts::Email.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_validity_delivery
|
11
|
+
@email.delivery_method = :brainwaves
|
12
|
+
assert_equal false, @email.valid?
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_smtp_delivery_method_for_notify
|
16
|
+
@email.delivery_method = :smtp
|
17
|
+
|
18
|
+
God::Contacts::Email.any_instance.expects(:notify_sendmail).never
|
19
|
+
God::Contacts::Email.any_instance.expects(:notify_smtp).once.returns(nil)
|
20
|
+
|
21
|
+
@email.notify('msg', Time.now, 'prio', 'cat', 'host')
|
22
|
+
assert_equal "sent email to dev@example.com via smtp", @email.info
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_sendmail_delivery_method_for_notify
|
26
|
+
@email.delivery_method = :sendmail
|
27
|
+
|
28
|
+
God::Contacts::Email.any_instance.expects(:notify_smtp).never
|
29
|
+
God::Contacts::Email.any_instance.expects(:notify_sendmail).once.returns(nil)
|
30
|
+
|
31
|
+
@email.notify('msg', Time.now, 'prio', 'cat', 'host')
|
32
|
+
assert_equal "sent email to dev@example.com via sendmail", @email.info
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
module God
|
4
|
+
class EventHandler
|
5
|
+
|
6
|
+
def self.actions=(value)
|
7
|
+
@@actions = value
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.actions
|
11
|
+
@@actions
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.handler=(value)
|
15
|
+
@@handler = value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class TestEventHandler < Minitest::Test
|
21
|
+
def setup
|
22
|
+
@h = God::EventHandler
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_register_one_event
|
26
|
+
pid = 4445
|
27
|
+
event = :proc_exit
|
28
|
+
block = lambda {
|
29
|
+
puts "Hi"
|
30
|
+
}
|
31
|
+
|
32
|
+
mock_handler = mock()
|
33
|
+
mock_handler.expects(:register_process).with(pid, [event])
|
34
|
+
@h.handler = mock_handler
|
35
|
+
|
36
|
+
@h.register(pid, event, &block)
|
37
|
+
assert_equal @h.actions, {pid => {event => block}}
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_register_multiple_events_per_process
|
41
|
+
pid = 4445
|
42
|
+
exit_block = lambda { puts "Hi" }
|
43
|
+
@h.actions = {pid => {:proc_exit => exit_block}}
|
44
|
+
|
45
|
+
mock_handler = mock()
|
46
|
+
mock_handler.expects(:register_process).with do |a, b|
|
47
|
+
a == pid &&
|
48
|
+
b.to_set == [:proc_exit, :proc_fork].to_set
|
49
|
+
end
|
50
|
+
@h.handler = mock_handler
|
51
|
+
|
52
|
+
fork_block = lambda { puts "Forking" }
|
53
|
+
@h.register(pid, :proc_fork, &fork_block)
|
54
|
+
assert_equal @h.actions, {pid => {:proc_exit => exit_block,
|
55
|
+
:proc_fork => fork_block }}
|
56
|
+
end
|
57
|
+
|
58
|
+
# JIRA PLATFORM-75
|
59
|
+
def test_call_should_check_for_pid_and_action_before_executing
|
60
|
+
exit_block = mock()
|
61
|
+
exit_block.expects(:call).times 1
|
62
|
+
@h.actions = {4445 => {:proc_exit => exit_block}}
|
63
|
+
@h.call(4446, :proc_exit) # shouldn't call, bad pid
|
64
|
+
@h.call(4445, :proc_fork) # shouldn't call, bad event
|
65
|
+
@h.call(4445, :proc_exit) # should call
|
66
|
+
end
|
67
|
+
|
68
|
+
def teardown
|
69
|
+
# Reset handler
|
70
|
+
@h.actions = {}
|
71
|
+
@h.load
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# This doesn't currently work:
|
76
|
+
#
|
77
|
+
# class TestEventHandlerOperational < Minitest::Test
|
78
|
+
# def test_operational
|
79
|
+
# God::EventHandler.start
|
80
|
+
# assert God::EventHandler.loaded?
|
81
|
+
# end
|
82
|
+
# end
|