god 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +43 -7
- data/Manifest.txt +20 -4
- data/Rakefile +1 -1
- data/bin/god +263 -195
- data/examples/events.god +66 -34
- data/examples/gravatar.god +25 -12
- data/init/god +42 -0
- data/lib/god/behavior.rb +9 -29
- data/lib/god/behaviors/clean_pid_file.rb +6 -2
- data/lib/god/behaviors/notify_when_flapping.rb +4 -4
- data/lib/god/condition.rb +48 -6
- data/lib/god/conditions/always.rb +5 -1
- data/lib/god/conditions/cpu_usage.rb +13 -5
- data/lib/god/conditions/degrading_lambda.rb +8 -3
- data/lib/god/conditions/flapping.rb +97 -0
- data/lib/god/conditions/http_response_code.rb +97 -0
- data/lib/god/conditions/lambda.rb +8 -2
- data/lib/god/conditions/memory_usage.rb +13 -5
- data/lib/god/conditions/process_exits.rb +11 -3
- data/lib/god/conditions/process_running.rb +22 -4
- data/lib/god/conditions/tries.rb +16 -5
- data/lib/god/configurable.rb +54 -0
- data/lib/god/contact.rb +106 -0
- data/lib/god/contacts/email.rb +73 -0
- data/lib/god/errors.rb +3 -0
- data/lib/god/hub.rb +138 -33
- data/lib/god/logger.rb +21 -4
- data/lib/god/metric.rb +3 -4
- data/lib/god/process.rb +93 -49
- data/lib/god/socket.rb +60 -0
- data/lib/god/task.rb +233 -0
- data/lib/god/trigger.rb +43 -0
- data/lib/god/watch.rb +48 -114
- data/lib/god.rb +216 -63
- data/test/configs/child_events/child_events.god +20 -1
- data/test/configs/child_polls/child_polls.god +26 -6
- data/test/configs/child_polls/simple_server.rb +10 -1
- data/test/configs/contact/contact.god +74 -0
- data/test/configs/contact/simple_server.rb +3 -0
- data/test/configs/daemon_events/daemon_events.god +5 -2
- data/test/configs/daemon_events/simple_server.rb +2 -0
- data/test/configs/daemon_events/simple_server_stop.rb +9 -0
- data/test/configs/degrading_lambda/degrading_lambda.god +1 -3
- data/test/configs/task/logs/.placeholder +0 -0
- data/test/configs/task/task.god +26 -0
- data/test/helper.rb +19 -11
- data/test/test_conditions_http_response_code.rb +115 -0
- data/test/test_conditions_process_running.rb +2 -2
- data/test/test_conditions_tries.rb +21 -0
- data/test/test_contact.rb +109 -0
- data/test/test_god.rb +101 -17
- data/test/test_hub.rb +64 -1
- data/test/test_process.rb +43 -56
- data/test/{test_server.rb → test_socket.rb} +6 -20
- data/test/test_task.rb +86 -0
- data/test/test_trigger.rb +59 -0
- data/test/test_watch.rb +32 -7
- metadata +27 -8
- data/lib/god/reporter.rb +0 -25
- data/lib/god/server.rb +0 -37
- data/test/test_reporter.rb +0 -18
data/test/helper.rb
CHANGED
@@ -42,23 +42,30 @@ module God
|
|
42
42
|
end
|
43
43
|
|
44
44
|
class FakeEventCondition < EventCondition
|
45
|
-
def
|
46
|
-
|
45
|
+
def register
|
46
|
+
end
|
47
|
+
def deregister
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
52
|
module Behaviors
|
52
53
|
class FakeBehavior < Behavior
|
54
|
+
def before_start
|
55
|
+
'foo'
|
56
|
+
end
|
57
|
+
def after_start
|
58
|
+
'bar'
|
59
|
+
end
|
53
60
|
end
|
54
61
|
end
|
55
62
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
63
|
+
module Contacts
|
64
|
+
class FakeContact < Contact
|
65
|
+
end
|
66
|
+
|
67
|
+
class InvalidContact
|
68
|
+
end
|
62
69
|
end
|
63
70
|
|
64
71
|
def self.reset
|
@@ -98,14 +105,15 @@ module Kernel
|
|
98
105
|
def abort(text)
|
99
106
|
raise SystemExit
|
100
107
|
end
|
108
|
+
def exit(code)
|
109
|
+
raise SystemExit
|
110
|
+
end
|
101
111
|
end
|
102
112
|
|
103
113
|
module Test::Unit::Assertions
|
104
114
|
def assert_abort
|
105
115
|
assert_raise SystemExit do
|
106
|
-
|
107
|
-
yield
|
108
|
-
end
|
116
|
+
yield
|
109
117
|
end
|
110
118
|
end
|
111
119
|
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestHttpResponseCode < Test::Unit::TestCase
|
4
|
+
def valid_condition
|
5
|
+
c = Conditions::HttpResponseCode.new()
|
6
|
+
c.watch = stub(:name => 'foo')
|
7
|
+
c.host = 'localhost'
|
8
|
+
c.port = 8080
|
9
|
+
c.path = '/'
|
10
|
+
c.timeout = 10
|
11
|
+
c.code_is = 200
|
12
|
+
c.times = 1
|
13
|
+
yield(c) if block_given?
|
14
|
+
c.prepare
|
15
|
+
c
|
16
|
+
end
|
17
|
+
|
18
|
+
# valid?
|
19
|
+
|
20
|
+
def test_valid_condition_is_valid
|
21
|
+
c = valid_condition
|
22
|
+
assert c.valid?
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_valid_should_return_false_if_both_code_is_and_code_is_not_are_set
|
26
|
+
c = valid_condition do |cc|
|
27
|
+
cc.code_is_not = 500
|
28
|
+
end
|
29
|
+
no_stdout { assert !c.valid? }
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_valid_should_return_false_if_no_host_set
|
33
|
+
c = valid_condition do |cc|
|
34
|
+
cc.host = nil
|
35
|
+
end
|
36
|
+
no_stdout { assert !c.valid? }
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_valid_should_return_false_if_no_port_set
|
40
|
+
c = valid_condition do |cc|
|
41
|
+
cc.port = nil
|
42
|
+
end
|
43
|
+
no_stdout { assert !c.valid? }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_valid_should_return_false_if_no_path_set
|
47
|
+
c = valid_condition do |cc|
|
48
|
+
cc.path = nil
|
49
|
+
end
|
50
|
+
no_stdout { assert !c.valid? }
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_valid_should_return_false_if_no_timeout_set
|
54
|
+
c = valid_condition do |cc|
|
55
|
+
cc.timeout = nil
|
56
|
+
end
|
57
|
+
no_stdout { assert !c.valid? }
|
58
|
+
end
|
59
|
+
|
60
|
+
# test
|
61
|
+
|
62
|
+
def test_test_should_return_false_if_code_is_is_set_to_200_but_response_is_500
|
63
|
+
c = valid_condition
|
64
|
+
Net::HTTP.expects(:start).yields(stub(:read_timeout= => nil, :head => stub(:code => 500)))
|
65
|
+
assert_equal false, c.test
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_test_should_return_false_if_code_is_not_is_set_to_200_and_response_is_200
|
69
|
+
c = valid_condition do |cc|
|
70
|
+
cc.code_is = nil
|
71
|
+
cc.code_is_not = [200]
|
72
|
+
end
|
73
|
+
Net::HTTP.expects(:start).yields(stub(:read_timeout= => nil, :head => stub(:code => 200)))
|
74
|
+
assert_equal false, c.test
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_test_should_return_true_if_code_is_is_set_to_200_and_response_is_200
|
78
|
+
c = valid_condition
|
79
|
+
Net::HTTP.expects(:start).yields(stub(:read_timeout= => nil, :head => stub(:code => 200)))
|
80
|
+
assert_equal true, c.test
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_test_should_return_false_if_code_is_not_is_set_to_200_but_response_is_500
|
84
|
+
c = valid_condition do |cc|
|
85
|
+
cc.code_is = nil
|
86
|
+
cc.code_is_not = [200]
|
87
|
+
end
|
88
|
+
Net::HTTP.expects(:start).yields(stub(:read_timeout= => nil, :head => stub(:code => 500)))
|
89
|
+
assert_equal true, c.test
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_test_should_return_false_if_code_is_is_set_to_200_but_response_times_out
|
93
|
+
c = valid_condition
|
94
|
+
Net::HTTP.expects(:start).raises(Timeout::Error, '')
|
95
|
+
assert_equal false, c.test
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_test_should_return_true_if_code_is_not_is_set_to_200_and_response_times_out
|
99
|
+
c = valid_condition do |cc|
|
100
|
+
cc.code_is = nil
|
101
|
+
cc.code_is_not = [200]
|
102
|
+
end
|
103
|
+
Net::HTTP.expects(:start).raises(Timeout::Error, '')
|
104
|
+
assert_equal true, c.test
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_test_should_return_true_if_code_is_is_set_to_200_and_response_is_200_twice_for_times_two_of_two
|
108
|
+
c = valid_condition do |cc|
|
109
|
+
cc.times = [2, 2]
|
110
|
+
end
|
111
|
+
Net::HTTP.expects(:start).yields(stub(:read_timeout= => nil, :head => stub(:code => 200))).times(2)
|
112
|
+
assert_equal false, c.test
|
113
|
+
assert_equal true, c.test
|
114
|
+
end
|
115
|
+
end
|
@@ -6,9 +6,9 @@ class TestConditionsProcessRunning < Test::Unit::TestCase
|
|
6
6
|
c = Conditions::ProcessRunning.new
|
7
7
|
c.running = r
|
8
8
|
|
9
|
-
c.stubs(:watch).returns(stub(:pid_file => ''))
|
9
|
+
c.stubs(:watch).returns(stub(:pid_file => '', :name => 'foo'))
|
10
10
|
|
11
|
-
assert_equal !r, c.test
|
11
|
+
no_stdout { assert_equal !r, c.test }
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -1,5 +1,16 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
|
+
class TestConditionsTries < Test::Unit::TestCase
|
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
|
+
no_stdout { assert !c.valid? }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
3
14
|
class TestConditionsTries < Test::Unit::TestCase
|
4
15
|
def setup
|
5
16
|
@c = Conditions::Tries.new
|
@@ -7,22 +18,30 @@ class TestConditionsTries < Test::Unit::TestCase
|
|
7
18
|
@c.prepare
|
8
19
|
end
|
9
20
|
|
21
|
+
# prepare
|
22
|
+
|
10
23
|
def test_prepare_should_create_timeline
|
11
24
|
assert 3, @c.instance_variable_get(:@timeline).instance_variable_get(:@max_size)
|
12
25
|
end
|
13
26
|
|
27
|
+
# test
|
28
|
+
|
14
29
|
def test_test_should_return_true_if_called_three_times_within_one_second
|
15
30
|
assert !@c.test
|
16
31
|
assert !@c.test
|
17
32
|
assert @c.test
|
18
33
|
end
|
19
34
|
|
35
|
+
# reset
|
36
|
+
|
20
37
|
def test_test_should_return_false_on_fourth_call_if_called_three_times_within_one_second
|
21
38
|
3.times { @c.test }
|
39
|
+
@c.reset
|
22
40
|
assert !@c.test
|
23
41
|
end
|
24
42
|
end
|
25
43
|
|
44
|
+
|
26
45
|
class TestConditionsTriesWithin < Test::Unit::TestCase
|
27
46
|
def setup
|
28
47
|
@c = Conditions::Tries.new
|
@@ -31,6 +50,8 @@ class TestConditionsTriesWithin < Test::Unit::TestCase
|
|
31
50
|
@c.prepare
|
32
51
|
end
|
33
52
|
|
53
|
+
# test
|
54
|
+
|
34
55
|
def test_test_should_return_true_if_called_three_times_within_one_second
|
35
56
|
assert !@c.test
|
36
57
|
assert !@c.test
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestContact < Test::Unit::TestCase
|
4
|
+
def test_exists
|
5
|
+
God::Contact
|
6
|
+
end
|
7
|
+
|
8
|
+
# generate
|
9
|
+
|
10
|
+
def test_generate_should_raise_on_invalid_kind
|
11
|
+
assert_raise(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_raise 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_raise 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_raise 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_raise 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_raise 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_raise ArgumentError do
|
98
|
+
Contact.normalize(input)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# notify
|
103
|
+
|
104
|
+
def test_notify_should_be_abstract
|
105
|
+
assert_raise(AbstractMethodNotOverriddenError) do
|
106
|
+
Contact.new.notify(:a, :b, :c, :d, :e)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/test/test_god.rb
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/helper'
|
|
2
2
|
|
3
3
|
class TestGod < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
|
5
|
+
God::Socket.stubs(:new).returns(true)
|
6
6
|
God.stubs(:setup).returns(true)
|
7
7
|
God.stubs(:validater).returns(true)
|
8
8
|
God.reset
|
@@ -12,31 +12,33 @@ class TestGod < Test::Unit::TestCase
|
|
12
12
|
Timer.get.timer.kill
|
13
13
|
end
|
14
14
|
|
15
|
-
#
|
15
|
+
# internal_init
|
16
16
|
|
17
17
|
def test_init_should_initialize_watches_to_empty_array
|
18
|
-
God.
|
18
|
+
God.internal_init { }
|
19
19
|
assert_equal Hash.new, God.watches
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
# init
|
23
|
+
|
24
|
+
def test_pid_file_directory_should_abort_if_called_after_watch
|
23
25
|
God.watch { |w| w.name = 'foo'; w.start = 'bar' }
|
24
26
|
|
25
27
|
assert_abort do
|
26
|
-
God.
|
28
|
+
God.pid_file_directory = 'foo'
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
32
|
# pid_file_directory
|
31
33
|
|
32
34
|
def test_pid_file_directory_should_return_default_if_not_set_explicitly
|
33
|
-
God.
|
35
|
+
God.internal_init
|
34
36
|
assert_equal '/var/run/god', God.pid_file_directory
|
35
37
|
end
|
36
38
|
|
37
39
|
def test_pid_file_directory_equals_should_set
|
38
|
-
God.init
|
39
40
|
God.pid_file_directory = '/foo'
|
41
|
+
God.internal_init
|
40
42
|
assert_equal '/foo', God.pid_file_directory
|
41
43
|
end
|
42
44
|
|
@@ -159,6 +161,7 @@ class TestGod < Test::Unit::TestCase
|
|
159
161
|
def test_unwatch_should_unmonitor_watch
|
160
162
|
God.watch { |w| w.name = 'bar'; w.start = 'bar' }
|
161
163
|
w = God.watches['bar']
|
164
|
+
w.state = :up
|
162
165
|
w.expects(:unmonitor)
|
163
166
|
God.unwatch(w)
|
164
167
|
end
|
@@ -194,6 +197,69 @@ class TestGod < Test::Unit::TestCase
|
|
194
197
|
assert !God.groups[w.group].include?(w)
|
195
198
|
end
|
196
199
|
|
200
|
+
# contact
|
201
|
+
|
202
|
+
def test_contact_should_ensure_init_is_called
|
203
|
+
God.contact(:fake_contact) { |c| c.name = 'tom' }
|
204
|
+
assert God.inited
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_contact_should_abort_on_invalid_contact_kind
|
208
|
+
assert_abort do
|
209
|
+
God.contact(:foo) { |c| c.name = 'tom' }
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_contact_should_create_and_store_contact
|
214
|
+
contact = nil
|
215
|
+
God.contact(:fake_contact) { |c| c.name = 'tom'; contact = c }
|
216
|
+
assert [contact], God.contacts
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_contact_should_add_to_group
|
220
|
+
God.contact(:fake_contact) { |c| c.name = 'tom'; c.group = 'devs' }
|
221
|
+
God.contact(:fake_contact) { |c| c.name = 'chris'; c.group = 'devs' }
|
222
|
+
assert 2, God.contact_groups.size
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_contact_should_abort_on_no_name
|
226
|
+
no_stdout do
|
227
|
+
assert_abort do
|
228
|
+
God.contact(:fake_contact) { |c| }
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_contact_should_abort_on_duplicate_contact_name
|
234
|
+
God.contact(:fake_contact) { |c| c.name = 'tom' }
|
235
|
+
assert_abort do
|
236
|
+
God.contact(:fake_contact) { |c| c.name = 'tom' }
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_contact_should_abort_on_contact_with_same_name_as_group
|
241
|
+
God.contact(:fake_contact) { |c| c.name = 'tom'; c.group = 'devs' }
|
242
|
+
assert_abort do
|
243
|
+
God.contact(:fake_contact) { |c| c.name = 'devs' }
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_contact_should_abort_on_contact_with_same_group_as_name
|
248
|
+
God.contact(:fake_contact) { |c| c.name = 'tom' }
|
249
|
+
assert_abort do
|
250
|
+
God.contact(:fake_contact) { |c| c.name = 'chris'; c.group = 'tom' }
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_contact_should_abort_if_contact_is_invalid
|
255
|
+
assert_abort do
|
256
|
+
God.contact(:fake_contact) do |c|
|
257
|
+
c.name = 'tom'
|
258
|
+
c.stubs(:valid?).returns(false)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
197
263
|
# control
|
198
264
|
|
199
265
|
def test_control_should_monitor_on_start
|
@@ -216,6 +282,7 @@ class TestGod < Test::Unit::TestCase
|
|
216
282
|
God.watch { |w| w.name = 'foo'; w.start = 'bar' }
|
217
283
|
|
218
284
|
w = God.watches['foo']
|
285
|
+
w.state = :up
|
219
286
|
w.expects(:unmonitor).returns(w)
|
220
287
|
w.expects(:action).with(:stop)
|
221
288
|
God.control('foo', 'stop')
|
@@ -225,6 +292,7 @@ class TestGod < Test::Unit::TestCase
|
|
225
292
|
God.watch { |w| w.name = 'foo'; w.start = 'bar' }
|
226
293
|
|
227
294
|
w = God.watches['foo']
|
295
|
+
w.state = :up
|
228
296
|
w.expects(:unmonitor).returns(w)
|
229
297
|
God.control('foo', 'unmonitor')
|
230
298
|
end
|
@@ -261,7 +329,7 @@ class TestGod < Test::Unit::TestCase
|
|
261
329
|
# terminate
|
262
330
|
|
263
331
|
def test_terminate_should_exit
|
264
|
-
God.expects(:exit!)
|
332
|
+
God.expects(:exit!)
|
265
333
|
God.terminate
|
266
334
|
end
|
267
335
|
|
@@ -282,6 +350,22 @@ class TestGod < Test::Unit::TestCase
|
|
282
350
|
assert_equal({'foo' => {:state => :unmonitored}}, God.status)
|
283
351
|
end
|
284
352
|
|
353
|
+
# running_log
|
354
|
+
|
355
|
+
def test_running_log_should_call_watch_log_since_on_main_log
|
356
|
+
God.watch { |w| w.name = 'foo'; w.start = 'bar' }
|
357
|
+
t = Time.now
|
358
|
+
LOG.expects(:watch_log_since).with('foo', t)
|
359
|
+
God.running_log('foo', t)
|
360
|
+
end
|
361
|
+
|
362
|
+
def test_running_log_should_raise_on_unknown_watch
|
363
|
+
God.internal_init
|
364
|
+
assert_raise(NoSuchWatchError) do
|
365
|
+
God.running_log('foo', Time.now)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
285
369
|
# running_load
|
286
370
|
|
287
371
|
def test_running_load_should_eval_code
|
@@ -293,7 +377,7 @@ class TestGod < Test::Unit::TestCase
|
|
293
377
|
EOF
|
294
378
|
|
295
379
|
no_stdout do
|
296
|
-
God.running_load(code)
|
380
|
+
God.running_load(code, '/foo/bar.god')
|
297
381
|
end
|
298
382
|
|
299
383
|
assert_equal 1, God.watches.size
|
@@ -309,7 +393,7 @@ class TestGod < Test::Unit::TestCase
|
|
309
393
|
|
310
394
|
Watch.any_instance.expects(:monitor)
|
311
395
|
no_stdout do
|
312
|
-
God.running_load(code)
|
396
|
+
God.running_load(code, '/foo/bar.god')
|
313
397
|
end
|
314
398
|
end
|
315
399
|
|
@@ -324,7 +408,7 @@ class TestGod < Test::Unit::TestCase
|
|
324
408
|
|
325
409
|
Watch.any_instance.expects(:monitor).never
|
326
410
|
no_stdout do
|
327
|
-
God.running_load(code)
|
411
|
+
God.running_load(code, '/foo/bar.god')
|
328
412
|
end
|
329
413
|
end
|
330
414
|
|
@@ -338,10 +422,10 @@ class TestGod < Test::Unit::TestCase
|
|
338
422
|
|
339
423
|
w = nil
|
340
424
|
no_stdout do
|
341
|
-
w = God.running_load(code)
|
425
|
+
w, e = *God.running_load(code, '/foo/bar.god')
|
342
426
|
end
|
343
427
|
assert_equal 1, w.size
|
344
|
-
assert_equal 'foo', w.first
|
428
|
+
assert_equal 'foo', w.first
|
345
429
|
end
|
346
430
|
|
347
431
|
def test_running_load_should_clear_pending_watches
|
@@ -353,7 +437,7 @@ class TestGod < Test::Unit::TestCase
|
|
353
437
|
EOF
|
354
438
|
|
355
439
|
no_stdout do
|
356
|
-
God.running_load(code)
|
440
|
+
God.running_load(code, '/foo/bar.god')
|
357
441
|
end
|
358
442
|
assert_equal 0, God.pending_watches.size
|
359
443
|
end
|
@@ -370,7 +454,7 @@ class TestGod < Test::Unit::TestCase
|
|
370
454
|
# start
|
371
455
|
|
372
456
|
def test_start_should_kick_off_a_server_instance
|
373
|
-
|
457
|
+
God::Socket.expects(:new).returns(true)
|
374
458
|
God.start
|
375
459
|
end
|
376
460
|
|
@@ -418,14 +502,14 @@ class TestGod < Test::Unit::TestCase
|
|
418
502
|
|
419
503
|
def test_at_exit_should_call_start
|
420
504
|
God.expects(:start).once
|
421
|
-
God.
|
505
|
+
God.at_exit
|
422
506
|
end
|
423
507
|
end
|
424
508
|
|
425
509
|
|
426
510
|
class TestGodOther < Test::Unit::TestCase
|
427
511
|
def setup
|
428
|
-
|
512
|
+
God::Socket.stubs(:new).returns(true)
|
429
513
|
God.internal_init
|
430
514
|
God.reset
|
431
515
|
end
|
data/test/test_hub.rb
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/helper'
|
|
2
2
|
|
3
3
|
class TestHub < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
|
5
|
+
God::Socket.stubs(:new).returns(true)
|
6
6
|
God.reset
|
7
7
|
|
8
8
|
God.watch do |w|
|
@@ -157,6 +157,40 @@ class TestHub < Test::Unit::TestCase
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
|
+
def test_handle_poll_should_notify_if_triggering
|
161
|
+
c = Conditions::FakePollCondition.new
|
162
|
+
c.interval = 10
|
163
|
+
c.notify = 'tom'
|
164
|
+
|
165
|
+
m = Metric.new(@watch, {true => :up})
|
166
|
+
Hub.attach(c, m)
|
167
|
+
|
168
|
+
c.expects(:test).returns(true)
|
169
|
+
Hub.expects(:notify)
|
170
|
+
|
171
|
+
no_stdout do
|
172
|
+
t = Hub.handle_poll(c)
|
173
|
+
t.join
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_handle_poll_should_not_notify_if_not_triggering
|
178
|
+
c = Conditions::FakePollCondition.new
|
179
|
+
c.interval = 10
|
180
|
+
c.notify = 'tom'
|
181
|
+
|
182
|
+
m = Metric.new(@watch, {true => :up})
|
183
|
+
Hub.attach(c, m)
|
184
|
+
|
185
|
+
c.expects(:test).returns(false)
|
186
|
+
Hub.expects(:notify).never
|
187
|
+
|
188
|
+
no_stdout do
|
189
|
+
t = Hub.handle_poll(c)
|
190
|
+
t.join
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
160
194
|
# handle_event
|
161
195
|
|
162
196
|
def test_handle_event_should_move
|
@@ -172,4 +206,33 @@ class TestHub < Test::Unit::TestCase
|
|
172
206
|
t.join
|
173
207
|
end
|
174
208
|
end
|
209
|
+
|
210
|
+
def test_handle_event_should_notify_if_triggering
|
211
|
+
c = Conditions::FakeEventCondition.new
|
212
|
+
c.notify = 'tom'
|
213
|
+
|
214
|
+
m = Metric.new(@watch, {true => :up})
|
215
|
+
Hub.attach(c, m)
|
216
|
+
|
217
|
+
Hub.expects(:notify)
|
218
|
+
|
219
|
+
no_stdout do
|
220
|
+
t = Hub.handle_event(c)
|
221
|
+
t.join
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_handle_event_should_not_notify_if_no_notify_set
|
226
|
+
c = Conditions::FakeEventCondition.new
|
227
|
+
|
228
|
+
m = Metric.new(@watch, {true => :up})
|
229
|
+
Hub.attach(c, m)
|
230
|
+
|
231
|
+
Hub.expects(:notify).never
|
232
|
+
|
233
|
+
no_stdout do
|
234
|
+
t = Hub.handle_event(c)
|
235
|
+
t.join
|
236
|
+
end
|
237
|
+
end
|
175
238
|
end
|