public
Fork of mojombo/god
Description: Ruby process monitor
Homepage: http://god.rubyforge.org
Clone URL: git://github.com/Bertg/god.git
move old hub tests into task
mojombo (author)
Fri Jan 25 13:03:24 -0800 2008
commit  c6804137e4bacd86dd5791c31e3a5d0ceec18d8b
tree    9922ac5824583d303d43397b671369f10c2f1506
parent  c6840c217deaae381fa0068d2b9bc2676095a3e9
...
304
305
306
307
 
308
309
310
311
312
313
...
319
320
321
 
322
323
324
...
367
368
369
 
370
371
372
...
304
305
306
 
307
308
309
 
310
311
312
...
318
319
320
321
322
323
324
...
367
368
369
370
371
372
373
0
@@ -304,10 +304,9 @@ module God
0
     #
0
     ###########################################################################
0
     
0
- # Asynchronously evaluate and handle the given poll condition. Handles logging
0
+ # Evaluate and handle the given poll condition. Handles logging
0
     # notifications, and moving to the new state if necessary
0
     # +condition+ is the Condition to handle
0
- # +phase+ is the phase of the Watch that should be matched
0
     #
0
     # Returns nothing
0
     def handle_poll(condition)
0
@@ -319,6 +318,7 @@ module God
0
       
0
       # log
0
       # messages = self.log_line(self, metric, condition, result)
0
+ messages = []
0
       
0
       # notify
0
       if condition.notify && self.trigger?(metric, result)
0
@@ -367,6 +367,7 @@ module God
0
       
0
       # log
0
       # messages = self.log_line(self, metric, condition, true)
0
+ messages = []
0
       
0
       # notify
0
       if condition.notify && self.trigger?(metric, true)
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-('01'..'20').each do |i|
0
+('01'..'40').each do |i|
0
   God.watch do |w|
0
     w.name = "stress-#{i}"
0
     w.start = "ruby " + File.join(File.dirname(__FILE__), *%w[simple_server.rb])
...
2
3
4
 
5
 
 
 
 
 
 
 
 
 
 
 
6
7
8
...
92
93
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
96
...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
0
@@ -2,7 +2,19 @@ require File.dirname(__FILE__) + '/helper'
0
 
0
 class TestTask < Test::Unit::TestCase
0
   def setup
0
+ God::Socket.stubs(:new).returns(true)
0
     God.internal_init
0
+ God.reset
0
+
0
+ God.watch do |w|
0
+ w.name = 'foo'
0
+ w.start = 'bar'
0
+ w.interval = 10
0
+ end
0
+
0
+ @watch = God.watches['foo']
0
+
0
+
0
     @task = Task.new
0
     @task.name = 'foo'
0
     @task.valid_states = [:foo, :bar]
0
@@ -92,4 +104,171 @@ class TestTask < Test::Unit::TestCase
0
     @task.driver.expects(:message).with(:action, [:foo, nil])
0
     @task.action(:foo, nil)
0
   end
0
+
0
+ # attach
0
+
0
+ def test_attach_should_schedule_for_poll_condition
0
+ c = Conditions::FakePollCondition.new
0
+ @task.driver.expects(:schedule).with(c, 0)
0
+ @task.attach(c)
0
+ end
0
+
0
+ def test_attach_should_regsiter_for_event_condition
0
+ c = Conditions::FakeEventCondition.new
0
+ c.expects(:register)
0
+ @task.attach(c)
0
+ end
0
+
0
+ # detach
0
+
0
+ def test_detach_should_reset_poll_condition
0
+ c = Conditions::FakePollCondition.new
0
+ c.expects(:reset)
0
+ c.expects(:deregister).never
0
+ @task.detach(c)
0
+ end
0
+
0
+ def test_detach_should_deregister_event_conditions
0
+ c = Conditions::FakeEventCondition.new
0
+ c.expects(:deregister).once
0
+ @task.detach(c)
0
+ end
0
+
0
+ # trigger
0
+
0
+ def test_trigger_should_send_message_to_driver
0
+ c = Conditions::FakePollCondition.new
0
+ @task.driver.expects(:message).with(:handle_event, [c])
0
+ @task.trigger(c)
0
+ end
0
+
0
+ # handle_poll
0
+
0
+ def test_handle_poll_no_change_should_reschedule
0
+ c = Conditions::FakePollCondition.new
0
+ c.watch = @task
0
+ c.interval = 10
0
+
0
+ m = Metric.new(@task, {true => :up})
0
+ @task.directory[c] = m
0
+
0
+ c.expects(:test).returns(false)
0
+ @task.driver.expects(:schedule)
0
+
0
+ no_stdout do
0
+ @task.handle_poll(c)
0
+ end
0
+ end
0
+
0
+ def test_handle_poll_change_should_move
0
+ c = Conditions::FakePollCondition.new
0
+ c.watch = @task
0
+ c.interval = 10
0
+
0
+ m = Metric.new(@task, {true => :up})
0
+ @task.directory[c] = m
0
+
0
+ c.expects(:test).returns(true)
0
+ @task.expects(:move).with(:up)
0
+
0
+ no_stdout do
0
+ @task.handle_poll(c)
0
+ end
0
+ end
0
+
0
+ def test_handle_poll_should_use_overridden_transition
0
+ c = Conditions::Tries.new
0
+ c.watch = @task
0
+ c.times = 1
0
+ c.transition = :start
0
+ c.prepare
0
+
0
+ m = Metric.new(@task, {true => :up})
0
+ @task.directory[c] = m
0
+
0
+ @task.expects(:move).with(:start)
0
+
0
+ no_stdout do
0
+ @task.handle_poll(c)
0
+ end
0
+ end
0
+
0
+ def test_handle_poll_should_notify_if_triggering
0
+ c = Conditions::FakePollCondition.new
0
+ c.watch = @task
0
+ c.interval = 10
0
+ c.notify = 'tom'
0
+
0
+ m = Metric.new(@task, {true => :up})
0
+ @task.directory[c] = m
0
+
0
+ c.expects(:test).returns(true)
0
+ @task.expects(:notify)
0
+
0
+ no_stdout do
0
+ @task.handle_poll(c)
0
+ end
0
+ end
0
+
0
+ def test_handle_poll_should_not_notify_if_not_triggering
0
+ c = Conditions::FakePollCondition.new
0
+ c.watch = @task
0
+ c.interval = 10
0
+ c.notify = 'tom'
0
+
0
+ m = Metric.new(@task, {true => :up})
0
+ @task.directory[c] = m
0
+
0
+ c.expects(:test).returns(false)
0
+ @task.expects(:notify).never
0
+
0
+ no_stdout do
0
+ @task.handle_poll(c)
0
+ end
0
+ end
0
+
0
+ # handle_event
0
+
0
+ def test_handle_event_should_move
0
+ c = Conditions::FakeEventCondition.new
0
+ c.watch = @task
0
+
0
+ m = Metric.new(@task, {true => :up})
0
+ @task.directory[c] = m
0
+
0
+ @task.expects(:move).with(:up)
0
+
0
+ no_stdout do
0
+ @task.handle_event(c)
0
+ end
0
+ end
0
+
0
+ def test_handle_event_should_notify_if_triggering
0
+ c = Conditions::FakeEventCondition.new
0
+ c.watch = @task
0
+ c.notify = 'tom'
0
+
0
+ m = Metric.new(@task, {true => :up})
0
+ @task.directory[c] = m
0
+
0
+ @task.expects(:notify)
0
+
0
+ no_stdout do
0
+ @task.handle_event(c)
0
+ end
0
+ end
0
+
0
+ def test_handle_event_should_not_notify_if_no_notify_set
0
+ c = Conditions::FakeEventCondition.new
0
+ c.watch = @task
0
+
0
+ m = Metric.new(@task, {true => :up})
0
+ @task.directory[c] = m
0
+
0
+ @task.expects(:notify).never
0
+
0
+ no_stdout do
0
+ @task.handle_event(c)
0
+ end
0
+ end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.