god 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Announce.txt +6 -6
- data/Gemfile +2 -0
- data/History.txt +19 -2
- data/{README.txt → LICENSE} +0 -37
- data/README.md +31 -0
- data/Rakefile +80 -38
- data/bin/god +21 -21
- data/doc/god.asciidoc +1487 -0
- data/doc/intro.asciidoc +20 -0
- data/ext/god/extconf.rb +3 -3
- data/ext/god/kqueue_handler.c +18 -18
- data/ext/god/netlink_handler.c +31 -31
- data/god.gemspec +24 -16
- data/lib/god.rb +261 -204
- data/lib/god/behavior.rb +14 -14
- data/lib/god/behaviors/clean_pid_file.rb +5 -5
- data/lib/god/behaviors/clean_unix_socket.rb +10 -10
- data/lib/god/behaviors/notify_when_flapping.rb +12 -12
- data/lib/god/cli/command.rb +59 -46
- data/lib/god/cli/run.rb +33 -37
- data/lib/god/cli/version.rb +6 -6
- data/lib/god/compat19.rb +1 -4
- data/lib/god/condition.rb +21 -21
- data/lib/god/conditions/always.rb +19 -6
- data/lib/god/conditions/complex.rb +18 -18
- data/lib/god/conditions/cpu_usage.rb +14 -14
- data/lib/god/conditions/degrading_lambda.rb +8 -8
- data/lib/god/conditions/disk_usage.rb +5 -5
- data/lib/god/conditions/flapping.rb +23 -23
- data/lib/god/conditions/http_response_code.rb +35 -19
- data/lib/god/conditions/lambda.rb +2 -2
- data/lib/god/conditions/memory_usage.rb +13 -13
- data/lib/god/conditions/process_exits.rb +14 -20
- data/lib/god/conditions/process_running.rb +16 -25
- data/lib/god/conditions/socket_responding.rb +132 -0
- data/lib/god/conditions/tries.rb +10 -10
- data/lib/god/configurable.rb +10 -10
- data/lib/god/contact.rb +20 -20
- data/lib/god/contacts/email.rb +7 -4
- data/lib/god/contacts/jabber.rb +1 -1
- data/lib/god/driver.rb +96 -64
- data/lib/god/errors.rb +9 -9
- data/lib/god/event_handler.rb +19 -19
- data/lib/god/event_handlers/dummy_handler.rb +4 -4
- data/lib/god/event_handlers/kqueue_handler.rb +3 -3
- data/lib/god/event_handlers/netlink_handler.rb +2 -2
- data/lib/god/logger.rb +13 -13
- data/lib/god/metric.rb +50 -22
- data/lib/god/process.rb +53 -52
- data/lib/god/registry.rb +7 -7
- data/lib/god/simple_logger.rb +14 -14
- data/lib/god/socket.rb +11 -11
- data/lib/god/sugar.rb +30 -15
- data/lib/god/sys_logger.rb +2 -2
- data/lib/god/system/portable_poller.rb +8 -8
- data/lib/god/system/process.rb +8 -8
- data/lib/god/system/slash_proc_poller.rb +13 -13
- data/lib/god/task.rb +237 -188
- data/lib/god/timeline.rb +5 -5
- data/lib/god/trigger.rb +11 -11
- data/lib/god/watch.rb +205 -53
- data/test/configs/child_events/child_events.god +5 -5
- data/test/configs/child_events/simple_server.rb +1 -1
- data/test/configs/child_polls/child_polls.god +4 -4
- data/test/configs/child_polls/simple_server.rb +4 -4
- data/test/configs/complex/complex.god +7 -7
- data/test/configs/complex/simple_server.rb +1 -1
- data/test/configs/contact/contact.god +1 -1
- data/test/configs/contact/simple_server.rb +1 -1
- data/test/configs/daemon_events/daemon_events.god +5 -5
- data/test/configs/daemon_events/simple_server.rb +1 -1
- data/test/configs/daemon_events/simple_server_stop.rb +1 -1
- data/test/configs/daemon_polls/daemon_polls.god +3 -3
- data/test/configs/daemon_polls/simple_server.rb +1 -1
- data/test/configs/degrading_lambda/degrading_lambda.god +3 -3
- data/test/configs/keepalive/keepalive.god +9 -0
- data/test/configs/keepalive/keepalive.rb +12 -0
- data/test/configs/lifecycle/lifecycle.god +2 -2
- data/test/configs/matias/matias.god +6 -6
- data/test/configs/real.rb +7 -7
- data/test/configs/running_load/running_load.god +2 -2
- data/test/configs/stop_options/simple_server.rb +1 -1
- data/test/configs/stress/simple_server.rb +1 -1
- data/test/configs/stress/stress.god +2 -2
- data/test/configs/task/task.god +5 -5
- data/test/configs/test.rb +7 -7
- data/test/helper.rb +8 -8
- data/test/test_behavior.rb +3 -3
- data/test/test_campfire.rb +1 -2
- data/test/test_condition.rb +10 -10
- data/test/test_conditions_disk_usage.rb +12 -12
- data/test/test_conditions_http_response_code.rb +24 -24
- data/test/test_conditions_process_running.rb +7 -7
- data/test/test_conditions_socket_responding.rb +122 -0
- data/test/test_conditions_tries.rb +12 -12
- data/test/test_contact.rb +19 -19
- data/test/test_driver.rb +17 -3
- data/test/test_event_handler.rb +12 -12
- data/test/test_god.rb +195 -117
- data/test/test_handlers_kqueue_handler.rb +4 -4
- data/test/test_jabber.rb +1 -1
- data/test/test_logger.rb +17 -17
- data/test/test_metric.rb +16 -16
- data/test/test_process.rb +47 -41
- data/test/test_prowl.rb +1 -1
- data/test/test_registry.rb +2 -2
- data/test/test_socket.rb +3 -3
- data/test/test_sugar.rb +7 -7
- data/test/test_system_portable_poller.rb +1 -1
- data/test/test_system_process.rb +5 -5
- data/test/test_task.rb +57 -57
- data/test/test_timeline.rb +8 -8
- data/test/test_trigger.rb +16 -16
- data/test/test_watch.rb +69 -62
- metadata +182 -69
- data/lib/god/dependency_graph.rb +0 -41
- data/lib/god/diagnostics.rb +0 -37
- data/test/test_dependency_graph.rb +0 -62
@@ -5,7 +5,7 @@ class TestSystemPortablePoller < Test::Unit::TestCase
|
|
5
5
|
pid = Process.pid
|
6
6
|
@process = System::PortablePoller.new(pid)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def test_time_string_to_seconds
|
10
10
|
assert_equal 0, @process.bypass.time_string_to_seconds('0:00:00')
|
11
11
|
assert_equal 0, @process.bypass.time_string_to_seconds('0:00:55')
|
data/test/test_system_process.rb
CHANGED
@@ -5,24 +5,24 @@ class TestSystemProcess < Test::Unit::TestCase
|
|
5
5
|
pid = Process.pid
|
6
6
|
@process = System::Process.new(pid)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def test_exists_should_return_true_for_running_process
|
10
10
|
assert_equal true, @process.exists?
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def test_exists_should_return_false_for_non_existant_process
|
14
14
|
assert_equal false, System::Process.new(9999999).exists?
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def test_memory
|
18
18
|
assert_kind_of Integer, @process.memory
|
19
19
|
assert @process.memory > 0
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def test_percent_memory
|
23
23
|
assert_kind_of Float, @process.percent_memory
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def test_percent_cpu
|
27
27
|
assert_kind_of Float, @process.percent_cpu
|
28
28
|
end
|
data/test/test_task.rb
CHANGED
@@ -10,69 +10,69 @@ class TestTask < Test::Unit::TestCase
|
|
10
10
|
@task.interval = 5
|
11
11
|
@task.prepare
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
# valid?
|
15
|
-
|
15
|
+
|
16
16
|
def test_valid_should_return_false_if_no_name
|
17
17
|
@task.name = nil
|
18
18
|
assert !@task.valid?
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def test_valid_should_return_false_if_no_valid_states
|
22
22
|
@task.valid_states = nil
|
23
23
|
assert !@task.valid?
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def test_valid_should_return_false_if_no_initial_state
|
27
27
|
@task.initial_state = nil
|
28
28
|
assert !@task.valid?
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
# transition
|
32
|
-
|
32
|
+
|
33
33
|
def test_transition_should_be_always_if_no_block_was_given
|
34
34
|
@task.transition(:foo, :bar)
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
|
36
|
+
assert_equal 5, @task.metrics.size
|
37
|
+
assert_equal Conditions::Always, @task.metrics[:foo].first.conditions.first.class
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
# method_missing
|
41
|
-
|
41
|
+
|
42
42
|
def test_method_missing_should_create_accessor_for_states
|
43
43
|
assert_nothing_raised do
|
44
44
|
@task.foo = 'testing'
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def test_method_missing_should_raise_for_non_states
|
49
49
|
assert_raise NoMethodError do
|
50
50
|
@task.baz = 5
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def test_method_missing_should_raise_for_non_setters
|
55
55
|
assert_raise NoMethodError do
|
56
56
|
@task.baz
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
# action
|
61
|
-
|
61
|
+
|
62
62
|
def test_action_should_send_string_commands_to_system
|
63
63
|
@task.foo = 'foo'
|
64
64
|
@task.driver.stubs(:in_driver_context?).returns(true)
|
65
65
|
@task.expects(:system).with('foo')
|
66
66
|
@task.action(:foo, nil)
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def test_action_should_call_lambda_commands
|
70
70
|
@task.foo = lambda { }
|
71
71
|
@task.driver.stubs(:in_driver_context?).returns(true)
|
72
72
|
@task.foo.expects(:call)
|
73
73
|
@task.action(:foo, nil)
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
def test_action_should_raise_not_implemented_on_non_string_or_lambda_action
|
77
77
|
@task.driver.stubs(:in_driver_context?).returns(true)
|
78
78
|
assert_raise NotImplementedError do
|
@@ -80,167 +80,167 @@ class TestTask < Test::Unit::TestCase
|
|
80
80
|
@task.action(:foo, nil)
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def test_action_from_outside_driver_should_send_message_to_driver
|
85
85
|
@task.foo = 'foo'
|
86
86
|
@task.driver.expects(:message).with(:action, [:foo, nil])
|
87
87
|
@task.action(:foo, nil)
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
# attach
|
91
|
-
|
91
|
+
|
92
92
|
def test_attach_should_schedule_for_poll_condition
|
93
93
|
c = Conditions::FakePollCondition.new
|
94
94
|
@task.driver.expects(:schedule).with(c, 0)
|
95
95
|
@task.attach(c)
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
def test_attach_should_regsiter_for_event_condition
|
99
99
|
c = Conditions::FakeEventCondition.new
|
100
100
|
c.expects(:register)
|
101
101
|
@task.attach(c)
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
# detach
|
105
|
-
|
105
|
+
|
106
106
|
def test_detach_should_reset_poll_condition
|
107
107
|
c = Conditions::FakePollCondition.new
|
108
108
|
c.expects(:reset)
|
109
109
|
c.expects(:deregister).never
|
110
110
|
@task.detach(c)
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
def test_detach_should_deregister_event_conditions
|
114
114
|
c = Conditions::FakeEventCondition.new
|
115
115
|
c.expects(:deregister).once
|
116
116
|
@task.detach(c)
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
# trigger
|
120
|
-
|
120
|
+
|
121
121
|
def test_trigger_should_send_message_to_driver
|
122
122
|
c = Conditions::FakePollCondition.new
|
123
123
|
@task.driver.expects(:message).with(:handle_event, [c])
|
124
124
|
@task.trigger(c)
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
# handle_poll
|
128
|
-
|
128
|
+
|
129
129
|
def test_handle_poll_no_change_should_reschedule
|
130
130
|
c = Conditions::FakePollCondition.new
|
131
131
|
c.watch = @task
|
132
132
|
c.interval = 10
|
133
|
-
|
133
|
+
|
134
134
|
m = Metric.new(@task, {true => :up})
|
135
135
|
@task.directory[c] = m
|
136
|
-
|
136
|
+
|
137
137
|
c.expects(:test).returns(false)
|
138
138
|
@task.driver.expects(:schedule)
|
139
139
|
@task.handle_poll(c)
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
def test_handle_poll_change_should_move
|
143
143
|
c = Conditions::FakePollCondition.new
|
144
144
|
c.watch = @task
|
145
145
|
c.interval = 10
|
146
|
-
|
146
|
+
|
147
147
|
m = Metric.new(@task, {true => :up})
|
148
148
|
@task.directory[c] = m
|
149
|
-
|
149
|
+
|
150
150
|
c.expects(:test).returns(true)
|
151
151
|
@task.expects(:move).with(:up)
|
152
152
|
@task.handle_poll(c)
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
def test_handle_poll_should_use_overridden_transition
|
156
156
|
c = Conditions::Tries.new
|
157
157
|
c.watch = @task
|
158
158
|
c.times = 1
|
159
159
|
c.transition = :start
|
160
160
|
c.prepare
|
161
|
-
|
161
|
+
|
162
162
|
m = Metric.new(@task, {true => :up})
|
163
163
|
@task.directory[c] = m
|
164
|
-
|
164
|
+
|
165
165
|
@task.expects(:move).with(:start)
|
166
166
|
@task.handle_poll(c)
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
169
|
def test_handle_poll_should_notify_if_triggering
|
170
170
|
c = Conditions::FakePollCondition.new
|
171
171
|
c.watch = @task
|
172
172
|
c.interval = 10
|
173
173
|
c.notify = 'tom'
|
174
|
-
|
174
|
+
|
175
175
|
m = Metric.new(@task, {true => :up})
|
176
176
|
@task.directory[c] = m
|
177
|
-
|
177
|
+
|
178
178
|
c.expects(:test).returns(true)
|
179
179
|
@task.expects(:notify)
|
180
180
|
@task.handle_poll(c)
|
181
181
|
end
|
182
|
-
|
182
|
+
|
183
183
|
def test_handle_poll_should_not_notify_if_not_triggering
|
184
184
|
c = Conditions::FakePollCondition.new
|
185
185
|
c.watch = @task
|
186
186
|
c.interval = 10
|
187
187
|
c.notify = 'tom'
|
188
|
-
|
188
|
+
|
189
189
|
m = Metric.new(@task, {true => :up})
|
190
190
|
@task.directory[c] = m
|
191
|
-
|
191
|
+
|
192
192
|
c.expects(:test).returns(false)
|
193
193
|
@task.expects(:notify).never
|
194
194
|
@task.handle_poll(c)
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
197
|
def test_handle_poll_unexpected_exception_should_reschedule
|
198
198
|
c = Conditions::FakePollCondition.new
|
199
199
|
c.watch = @task
|
200
200
|
c.interval = 10
|
201
|
-
|
201
|
+
|
202
202
|
m = Metric.new(@task, {true => :up})
|
203
203
|
@task.directory[c] = m
|
204
|
-
|
204
|
+
|
205
205
|
c.expects(:test).raises(StandardError)
|
206
206
|
@task.driver.expects(:schedule)
|
207
|
-
|
207
|
+
|
208
208
|
@task.handle_poll(c)
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
# handle_event
|
212
|
-
|
212
|
+
|
213
213
|
def test_handle_event_should_move
|
214
214
|
c = Conditions::FakeEventCondition.new
|
215
215
|
c.watch = @task
|
216
|
-
|
216
|
+
|
217
217
|
m = Metric.new(@task, {true => :up})
|
218
218
|
@task.directory[c] = m
|
219
|
-
|
219
|
+
|
220
220
|
@task.expects(:move).with(:up)
|
221
221
|
@task.handle_event(c)
|
222
222
|
end
|
223
|
-
|
223
|
+
|
224
224
|
def test_handle_event_should_notify_if_triggering
|
225
225
|
c = Conditions::FakeEventCondition.new
|
226
226
|
c.watch = @task
|
227
227
|
c.notify = 'tom'
|
228
|
-
|
228
|
+
|
229
229
|
m = Metric.new(@task, {true => :up})
|
230
230
|
@task.directory[c] = m
|
231
|
-
|
231
|
+
|
232
232
|
@task.expects(:notify)
|
233
233
|
@task.handle_event(c)
|
234
234
|
end
|
235
|
-
|
235
|
+
|
236
236
|
def test_handle_event_should_not_notify_if_no_notify_set
|
237
237
|
c = Conditions::FakeEventCondition.new
|
238
238
|
c.watch = @task
|
239
|
-
|
239
|
+
|
240
240
|
m = Metric.new(@task, {true => :up})
|
241
241
|
@task.directory[c] = m
|
242
|
-
|
242
|
+
|
243
243
|
@task.expects(:notify).never
|
244
244
|
@task.handle_event(c)
|
245
245
|
end
|
246
|
-
end
|
246
|
+
end
|
data/test/test_timeline.rb
CHANGED
@@ -4,32 +4,32 @@ class TestTimeline < Test::Unit::TestCase
|
|
4
4
|
def setup
|
5
5
|
@timeline = Timeline.new(5)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def test_new_should_be_empty
|
9
9
|
assert_equal 0, @timeline.size
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def test_should_not_grow_to_more_than_size
|
13
13
|
(1..10).each do |i|
|
14
14
|
@timeline.push(i)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
assert_equal [6, 7, 8, 9, 10], @timeline
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def test_clear_should_clear_array
|
21
21
|
@timeline << 1
|
22
22
|
assert_equal [1], @timeline
|
23
23
|
assert_equal [], @timeline.clear
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# def test_benchmark
|
27
27
|
# require 'benchmark'
|
28
|
-
#
|
28
|
+
#
|
29
29
|
# count = 1_000_000
|
30
|
-
#
|
30
|
+
#
|
31
31
|
# t = Timeline.new(10)
|
32
|
-
#
|
32
|
+
#
|
33
33
|
# Benchmark.bmbm do |x|
|
34
34
|
# x.report("go") { count.times { t.push(5) } }
|
35
35
|
# end
|
data/test/test_trigger.rb
CHANGED
@@ -4,56 +4,56 @@ class TestTrigger < Test::Unit::TestCase
|
|
4
4
|
def setup
|
5
5
|
Trigger.reset
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
# base case
|
9
|
-
|
9
|
+
|
10
10
|
def test_should_have_empty_triggers
|
11
11
|
assert_equal({}, Trigger.triggers)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
# register
|
15
|
-
|
15
|
+
|
16
16
|
def test_register_should_add_condition_to_triggers
|
17
17
|
c = Condition.new
|
18
18
|
c.watch = stub(:name => 'foo')
|
19
19
|
Trigger.register(c)
|
20
|
-
|
20
|
+
|
21
21
|
assert_equal({'foo' => [c]}, Trigger.triggers)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def test_register_should_add_condition_to_triggers_twice
|
25
25
|
watch = stub(:name => 'foo')
|
26
26
|
c = Condition.new
|
27
27
|
c.watch = watch
|
28
28
|
Trigger.register(c)
|
29
|
-
|
29
|
+
|
30
30
|
c2 = Condition.new
|
31
31
|
c2.watch = watch
|
32
32
|
Trigger.register(c2)
|
33
|
-
|
33
|
+
|
34
34
|
assert_equal({'foo' => [c, c2]}, Trigger.triggers)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
# deregister
|
38
|
-
|
38
|
+
|
39
39
|
def test_deregister_should_remove_condition_from_triggers
|
40
40
|
c = Condition.new
|
41
41
|
c.watch = stub(:name => 'foo')
|
42
42
|
Trigger.register(c)
|
43
43
|
Trigger.deregister(c)
|
44
|
-
|
44
|
+
|
45
45
|
assert_equal({}, Trigger.triggers)
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
# broadcast
|
49
|
-
|
49
|
+
|
50
50
|
def test_broadcast_should_call_process_on_each_condition
|
51
51
|
c = Condition.new
|
52
52
|
c.watch = stub(:name => 'foo')
|
53
53
|
Trigger.register(c)
|
54
|
-
|
54
|
+
|
55
55
|
c.expects(:process).with(:state_change, [:up, :start])
|
56
|
-
|
56
|
+
|
57
57
|
Trigger.broadcast(c.watch, :state_change, [:up, :start])
|
58
58
|
end
|
59
|
-
end
|
59
|
+
end
|
data/test/test_watch.rb
CHANGED
@@ -9,19 +9,19 @@ class TestWatch < Test::Unit::TestCase
|
|
9
9
|
@watch.stop = lambda { }
|
10
10
|
@watch.prepare
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
# new
|
14
|
-
|
14
|
+
|
15
15
|
def test_new_should_have_no_behaviors
|
16
16
|
assert_equal [], @watch.behaviors
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def test_new_should_have_no_metrics
|
20
20
|
Watch::VALID_STATES.each do |state|
|
21
21
|
assert_equal [], @watch.metrics[state]
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def test_new_should_have_standard_attributes
|
26
26
|
assert_nothing_raised do
|
27
27
|
@watch.name = 'foo'
|
@@ -32,41 +32,41 @@ class TestWatch < Test::Unit::TestCase
|
|
32
32
|
@watch.grace = 5
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def test_new_should_have_unmonitored_state
|
37
37
|
assert_equal :unmonitored, @watch.state
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
# valid?
|
41
|
-
|
41
|
+
|
42
42
|
def test_valid?
|
43
43
|
God::Process.any_instance.expects(:valid?)
|
44
44
|
@watch.valid?
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
# behavior
|
48
|
-
|
48
|
+
|
49
49
|
def test_behavior_should_record_behavior
|
50
50
|
beh = nil
|
51
51
|
@watch.behavior(:fake_behavior) { |b| beh = b }
|
52
52
|
assert_equal 1, @watch.behaviors.size
|
53
53
|
assert_equal beh, @watch.behaviors.first
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def test_invalid_behavior_should_abort
|
57
57
|
assert_abort do
|
58
58
|
@watch.behavior(:invalid)
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
# transition
|
63
|
-
|
63
|
+
|
64
64
|
def test_transition_should_abort_on_invalid_start_state
|
65
65
|
assert_abort do
|
66
66
|
@watch.transition(:foo, :bar)
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def test_transition_should_accept_all_valid_start_states
|
71
71
|
assert_nothing_raised do
|
72
72
|
Watch::VALID_STATES.each do |state|
|
@@ -74,35 +74,42 @@ class TestWatch < Test::Unit::TestCase
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def test_transition_should_create_and_record_a_metric_for_the_given_start_state
|
79
79
|
@watch.transition(:init, :start) { }
|
80
80
|
assert_equal 1, @watch.metrics[:init].size
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
# lifecycle
|
84
|
-
|
84
|
+
|
85
85
|
def test_lifecycle_should_create_and_record_a_metric_for_nil_start_state
|
86
86
|
@watch.lifecycle { }
|
87
87
|
assert_equal 1, @watch.metrics[nil].size
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
|
+
# keepalive
|
91
|
+
|
92
|
+
def test_keepalive_should_place_metrics_on_up_state
|
93
|
+
@watch.keepalive(:memory_max => 5.megabytes, :cpu_max => 50.percent)
|
94
|
+
assert_equal 2, @watch.metrics[:up].size
|
95
|
+
end
|
96
|
+
|
90
97
|
# start_if
|
91
|
-
|
98
|
+
|
92
99
|
def test_start_if_should_place_a_metric_on_up_state
|
93
100
|
@watch.start_if { }
|
94
101
|
assert_equal 1, @watch.metrics[:up].size
|
95
102
|
end
|
96
|
-
|
103
|
+
|
97
104
|
# restart_if
|
98
|
-
|
105
|
+
|
99
106
|
def test_restart_if_should_place_a_metric_on_up_state
|
100
107
|
@watch.restart_if { }
|
101
108
|
assert_equal 1, @watch.metrics[:up].size
|
102
109
|
end
|
103
|
-
|
110
|
+
|
104
111
|
# monitor
|
105
|
-
|
112
|
+
|
106
113
|
def test_monitor_should_move_to_init_if_available
|
107
114
|
@watch.instance_eval do
|
108
115
|
transition(:init, :up) { }
|
@@ -110,27 +117,27 @@ class TestWatch < Test::Unit::TestCase
|
|
110
117
|
@watch.expects(:move).with(:init)
|
111
118
|
@watch.monitor
|
112
119
|
end
|
113
|
-
|
120
|
+
|
114
121
|
def test_monitor_should_move_to_up_if_no_init_available
|
115
122
|
@watch.expects(:move).with(:up)
|
116
123
|
@watch.monitor
|
117
124
|
end
|
118
|
-
|
125
|
+
|
119
126
|
# unmonitor
|
120
|
-
|
127
|
+
|
121
128
|
def test_unmonitor_should_move_to_nil
|
122
129
|
@watch.expects(:move).with(:unmonitored)
|
123
130
|
@watch.unmonitor
|
124
131
|
end
|
125
|
-
|
132
|
+
|
126
133
|
# move
|
127
|
-
|
134
|
+
|
128
135
|
def test_move_should_not_clean_up_if_from_state_is_nil
|
129
136
|
@watch.driver.stubs(:in_driver_context?).returns(true)
|
130
137
|
@watch.driver.expects(:message).never
|
131
|
-
|
138
|
+
|
132
139
|
metric = nil
|
133
|
-
|
140
|
+
|
134
141
|
@watch.instance_eval do
|
135
142
|
transition(:init, :up) do |on|
|
136
143
|
metric = on
|
@@ -140,18 +147,18 @@ class TestWatch < Test::Unit::TestCase
|
|
140
147
|
end
|
141
148
|
end
|
142
149
|
end
|
143
|
-
|
150
|
+
|
144
151
|
metric.expects(:disable).never
|
145
|
-
|
152
|
+
|
146
153
|
@watch.move(:init)
|
147
154
|
end
|
148
|
-
|
155
|
+
|
149
156
|
def test_move_should_clean_up_from_state_if_not_nil
|
150
157
|
@watch.driver.stubs(:in_driver_context?).returns(true)
|
151
158
|
@watch.driver.expects(:message).never
|
152
|
-
|
159
|
+
|
153
160
|
metric = nil
|
154
|
-
|
161
|
+
|
155
162
|
@watch.instance_eval do
|
156
163
|
transition(:init, :up) do |on|
|
157
164
|
metric = on
|
@@ -161,40 +168,40 @@ class TestWatch < Test::Unit::TestCase
|
|
161
168
|
end
|
162
169
|
end
|
163
170
|
end
|
164
|
-
|
171
|
+
|
165
172
|
@watch.move(:init)
|
166
|
-
|
173
|
+
|
167
174
|
metric.expects(:disable)
|
168
|
-
|
175
|
+
|
169
176
|
@watch.move(:up)
|
170
177
|
end
|
171
|
-
|
178
|
+
|
172
179
|
def test_move_should_call_action
|
173
180
|
@watch.driver.stubs(:in_driver_context?).returns(true)
|
174
181
|
@watch.driver.expects(:message).never
|
175
|
-
|
182
|
+
|
176
183
|
@watch.expects(:action).with(:start)
|
177
|
-
|
184
|
+
|
178
185
|
@watch.move(:start)
|
179
186
|
end
|
180
|
-
|
187
|
+
|
181
188
|
def test_move_should_move_to_up_state_if_no_start_or_restart_metric
|
182
189
|
@watch.driver.stubs(:in_driver_context?).returns(true)
|
183
190
|
@watch.driver.expects(:message).never
|
184
|
-
|
191
|
+
|
185
192
|
[:start, :restart].each do |state|
|
186
193
|
@watch.expects(:action)
|
187
194
|
@watch.move(state)
|
188
195
|
assert_equal :up, @watch.state
|
189
196
|
end
|
190
197
|
end
|
191
|
-
|
198
|
+
|
192
199
|
def test_move_should_enable_destination_metric
|
193
200
|
@watch.driver.stubs(:in_driver_context?).returns(true)
|
194
201
|
@watch.driver.expects(:message).never
|
195
|
-
|
202
|
+
|
196
203
|
metric = nil
|
197
|
-
|
204
|
+
|
198
205
|
@watch.instance_eval do
|
199
206
|
transition(:init, :up) do |on|
|
200
207
|
metric = on
|
@@ -204,53 +211,53 @@ class TestWatch < Test::Unit::TestCase
|
|
204
211
|
end
|
205
212
|
end
|
206
213
|
end
|
207
|
-
|
214
|
+
|
208
215
|
metric.expects(:enable)
|
209
|
-
|
216
|
+
|
210
217
|
@watch.move(:init)
|
211
218
|
end
|
212
|
-
|
219
|
+
|
213
220
|
# action
|
214
|
-
|
221
|
+
|
215
222
|
def test_action_should_pass_start_and_stop_actions_to_call_action
|
216
223
|
@watch.driver.stubs(:in_driver_context?).returns(true)
|
217
224
|
@watch.driver.expects(:message).never
|
218
|
-
|
225
|
+
|
219
226
|
c = Conditions::FakePollCondition.new
|
220
227
|
[:start, :stop].each do |cmd|
|
221
228
|
@watch.expects(:call_action).with(c, cmd)
|
222
229
|
@watch.action(cmd, c)
|
223
230
|
end
|
224
231
|
end
|
225
|
-
|
232
|
+
|
226
233
|
def test_action_should_do_stop_then_start_if_no_restart_command
|
227
234
|
@watch.driver.stubs(:in_driver_context?).returns(true)
|
228
235
|
@watch.driver.expects(:message).never
|
229
|
-
|
236
|
+
|
230
237
|
c = Conditions::FakePollCondition.new
|
231
238
|
@watch.expects(:call_action).with(c, :stop)
|
232
239
|
@watch.expects(:call_action).with(c, :start)
|
233
240
|
@watch.action(:restart, c)
|
234
241
|
end
|
235
|
-
|
242
|
+
|
236
243
|
def test_action_should_restart_to_call_action_if_present
|
237
244
|
@watch.driver.stubs(:in_driver_context?).returns(true)
|
238
245
|
@watch.driver.expects(:message).never
|
239
|
-
|
246
|
+
|
240
247
|
@watch.restart = lambda { }
|
241
248
|
c = Conditions::FakePollCondition.new
|
242
249
|
@watch.expects(:call_action).with(c, :restart)
|
243
250
|
@watch.action(:restart, c)
|
244
251
|
end
|
245
|
-
|
252
|
+
|
246
253
|
# call_action
|
247
|
-
|
254
|
+
|
248
255
|
def test_call_action
|
249
256
|
c = Conditions::FakePollCondition.new
|
250
257
|
God::Process.any_instance.expects(:call_action).with(:start)
|
251
258
|
@watch.call_action(c, :start)
|
252
259
|
end
|
253
|
-
|
260
|
+
|
254
261
|
def test_call_action_should_call_before_start_when_behavior_has_that
|
255
262
|
@watch.behavior(:fake_behavior)
|
256
263
|
c = Conditions::FakePollCondition.new
|
@@ -258,7 +265,7 @@ class TestWatch < Test::Unit::TestCase
|
|
258
265
|
Behaviors::FakeBehavior.any_instance.expects(:before_start)
|
259
266
|
@watch.call_action(c, :start)
|
260
267
|
end
|
261
|
-
|
268
|
+
|
262
269
|
def test_call_action_should_call_after_start_when_behavior_has_that
|
263
270
|
@watch.behavior(:fake_behavior)
|
264
271
|
c = Conditions::FakePollCondition.new
|
@@ -266,14 +273,14 @@ class TestWatch < Test::Unit::TestCase
|
|
266
273
|
Behaviors::FakeBehavior.any_instance.expects(:after_start)
|
267
274
|
@watch.call_action(c, :start)
|
268
275
|
end
|
269
|
-
|
276
|
+
|
270
277
|
# canonical_hash_form
|
271
|
-
|
278
|
+
|
272
279
|
def test_canonical_hash_form_should_convert_symbol_to_hash
|
273
280
|
assert_equal({true => :foo}, @watch.canonical_hash_form(:foo))
|
274
281
|
end
|
275
|
-
|
282
|
+
|
276
283
|
def test_canonical_hash_form_should_convert_hash_to_hash
|
277
284
|
assert_equal({true => :foo}, @watch.canonical_hash_form(true => :foo))
|
278
285
|
end
|
279
|
-
end
|
286
|
+
end
|