god 0.13.4 → 0.13.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.txt +13 -0
- data/doc/god.asciidoc +50 -8
- data/ext/god/extconf.rb +1 -0
- data/ext/god/kqueue_handler.c +9 -1
- data/ext/god/netlink_handler.c +17 -0
- data/god.gemspec +12 -3
- data/lib/god.rb +3 -1
- data/lib/god/contacts/slack.rb +100 -0
- data/lib/god/contacts/statsd.rb +46 -0
- data/lib/god/contacts/webhook.rb +1 -0
- data/lib/god/process.rb +10 -5
- data/test/helper.rb +8 -3
- data/test/test_airbrake.rb +1 -1
- data/test/test_behavior.rb +2 -2
- data/test/test_campfire.rb +1 -1
- data/test/test_condition.rb +3 -3
- data/test/test_conditions_disk_usage.rb +1 -1
- data/test/test_conditions_http_response_code.rb +1 -1
- data/test/test_conditions_process_running.rb +1 -1
- data/test/test_conditions_socket_responding.rb +1 -1
- data/test/test_conditions_tries.rb +3 -3
- data/test/test_contact.rb +9 -9
- data/test/test_driver.rb +4 -3
- data/test/test_email.rb +1 -1
- data/test/test_event_handler.rb +2 -2
- data/test/test_god.rb +9 -7
- data/test/test_handlers_kqueue_handler.rb +1 -1
- data/test/test_hipchat.rb +1 -1
- data/test/test_jabber.rb +1 -1
- data/test/test_logger.rb +3 -3
- data/test/test_metric.rb +1 -1
- data/test/test_process.rb +7 -3
- data/test/test_prowl.rb +1 -1
- data/test/test_registry.rb +1 -1
- data/test/test_slack.rb +56 -0
- data/test/test_socket.rb +1 -1
- data/test/test_statsd.rb +22 -0
- data/test/test_sugar.rb +1 -1
- data/test/test_system_portable_poller.rb +1 -1
- data/test/test_system_process.rb +1 -1
- data/test/test_task.rb +4 -4
- data/test/test_timeline.rb +1 -1
- data/test/test_trigger.rb +5 -1
- data/test/test_watch.rb +1 -1
- data/test/test_webhook.rb +1 -1
- metadata +240 -223
data/test/helper.rb
CHANGED
@@ -7,7 +7,8 @@ require File.join(File.dirname(__FILE__), *%w[.. lib god sys_logger])
|
|
7
7
|
require File.join(File.dirname(__FILE__), *%w[.. lib god])
|
8
8
|
God::EventHandler.load
|
9
9
|
|
10
|
-
require '
|
10
|
+
require 'minitest/autorun'
|
11
|
+
require 'minitest/unit'
|
11
12
|
require 'set'
|
12
13
|
|
13
14
|
include God
|
@@ -115,12 +116,16 @@ end
|
|
115
116
|
# end
|
116
117
|
# end
|
117
118
|
|
118
|
-
module
|
119
|
+
module Minitest::Assertions
|
119
120
|
def assert_abort
|
120
|
-
|
121
|
+
assert_raises SystemExit do
|
121
122
|
yield
|
122
123
|
end
|
123
124
|
end
|
125
|
+
|
126
|
+
def assert_nothing_raised
|
127
|
+
yield
|
128
|
+
end
|
124
129
|
end
|
125
130
|
|
126
131
|
# This allows you to be a good OOP citizen and honor encapsulation, but
|
data/test/test_airbrake.rb
CHANGED
data/test/test_behavior.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
|
-
class TestBehavior < Test
|
3
|
+
class TestBehavior < Minitest::Test
|
4
4
|
def test_generate_should_return_an_object_corresponding_to_the_given_type
|
5
5
|
assert_equal Behaviors::FakeBehavior, Behavior.generate(:fake_behavior, nil).class
|
6
6
|
end
|
7
7
|
|
8
8
|
def test_generate_should_raise_on_invalid_type
|
9
|
-
|
9
|
+
assert_raises NoSuchBehaviorError do
|
10
10
|
Behavior.generate(:foo, nil)
|
11
11
|
end
|
12
12
|
end
|
data/test/test_campfire.rb
CHANGED
data/test/test_condition.rb
CHANGED
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/helper'
|
|
3
3
|
class BadlyImplementedCondition < PollCondition
|
4
4
|
end
|
5
5
|
|
6
|
-
class TestCondition < Test
|
6
|
+
class TestCondition < Minitest::Test
|
7
7
|
|
8
8
|
# generate
|
9
9
|
|
@@ -12,7 +12,7 @@ class TestCondition < Test::Unit::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_generate_should_raise_on_invalid_type
|
15
|
-
|
15
|
+
assert_raises NoSuchConditionError do
|
16
16
|
Condition.generate(:foo, nil)
|
17
17
|
end
|
18
18
|
end
|
@@ -45,7 +45,7 @@ class TestCondition < Test::Unit::TestCase
|
|
45
45
|
def test_test_should_raise_if_not_defined_in_subclass
|
46
46
|
c = BadlyImplementedCondition.new
|
47
47
|
|
48
|
-
|
48
|
+
assert_raises AbstractMethodNotOverriddenError do
|
49
49
|
c.test
|
50
50
|
end
|
51
51
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
|
-
class TestConditionsProcessRunning < Test
|
3
|
+
class TestConditionsProcessRunning < Minitest::Test
|
4
4
|
def test_missing_pid_file_returns_opposite
|
5
5
|
[true, false].each do |r|
|
6
6
|
c = Conditions::ProcessRunning.new
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
|
-
class TestConditionsTries < Test
|
3
|
+
class TestConditionsTries < Minitest::Test
|
4
4
|
# valid?
|
5
5
|
|
6
6
|
def test_valid_should_return_false_if_times_not_set
|
@@ -11,7 +11,7 @@ class TestConditionsTries < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
|
14
|
-
class TestConditionsTries < Test
|
14
|
+
class TestConditionsTries < Minitest::Test
|
15
15
|
def setup
|
16
16
|
@c = Conditions::Tries.new
|
17
17
|
@c.times = 3
|
@@ -42,7 +42,7 @@ class TestConditionsTries < Test::Unit::TestCase
|
|
42
42
|
end
|
43
43
|
|
44
44
|
|
45
|
-
class TestConditionsTriesWithin < Test
|
45
|
+
class TestConditionsTriesWithin < Minitest::Test
|
46
46
|
def setup
|
47
47
|
@c = Conditions::Tries.new
|
48
48
|
@c.times = 3
|
data/test/test_contact.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
|
-
class TestContact < Test
|
3
|
+
class TestContact < Minitest::Test
|
4
4
|
def test_exists
|
5
5
|
God::Contact
|
6
6
|
end
|
@@ -8,7 +8,7 @@ class TestContact < Test::Unit::TestCase
|
|
8
8
|
# generate
|
9
9
|
|
10
10
|
def test_generate_should_raise_on_invalid_kind
|
11
|
-
|
11
|
+
assert_raises(NoSuchContactError) do
|
12
12
|
Contact.generate(:invalid)
|
13
13
|
end
|
14
14
|
end
|
@@ -59,42 +59,42 @@ class TestContact < Test::Unit::TestCase
|
|
59
59
|
|
60
60
|
def test_normalize_should_raise_on_non_string_array_hash
|
61
61
|
input = 1
|
62
|
-
|
62
|
+
assert_raises ArgumentError do
|
63
63
|
Contact.normalize(input)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_normalize_should_raise_on_non_string_array_contacts_key
|
68
68
|
input = {:contacts => 1}
|
69
|
-
|
69
|
+
assert_raises ArgumentError do
|
70
70
|
Contact.normalize(input)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_normalize_should_raise_on_non_string_containing_array
|
75
75
|
input = [1]
|
76
|
-
|
76
|
+
assert_raises ArgumentError do
|
77
77
|
Contact.normalize(input)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
def test_normalize_should_raise_on_non_string_containing_array_contacts_key
|
82
82
|
input = {:contacts => [1]}
|
83
|
-
|
83
|
+
assert_raises ArgumentError do
|
84
84
|
Contact.normalize(input)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
88
|
def test_normalize_should_raise_on_absent_contacts_key
|
89
89
|
input = {}
|
90
|
-
|
90
|
+
assert_raises ArgumentError do
|
91
91
|
Contact.normalize(input)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
def test_normalize_should_raise_on_extra_keys
|
96
96
|
input = {:contacts => ['tom'], :priority => 1, :category => 'product', :extra => 'foo'}
|
97
|
-
|
97
|
+
assert_raises ArgumentError do
|
98
98
|
Contact.normalize(input)
|
99
99
|
end
|
100
100
|
end
|
@@ -102,7 +102,7 @@ class TestContact < Test::Unit::TestCase
|
|
102
102
|
# notify
|
103
103
|
|
104
104
|
def test_notify_should_be_abstract
|
105
|
-
|
105
|
+
assert_raises(AbstractMethodNotOverriddenError) do
|
106
106
|
Contact.new.notify(:a, :b, :c, :d, :e)
|
107
107
|
end
|
108
108
|
end
|
data/test/test_driver.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
|
-
class TestDriver < Test
|
3
|
+
class TestDriver < Minitest::Test
|
4
4
|
def setup
|
5
5
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def test_push_pop_wait
|
9
|
-
eq = God::DriverEventQueue.new
|
10
9
|
|
11
|
-
|
10
|
+
eq = God::DriverEventQueue.new
|
11
|
+
cond = eq.instance_variable_get(:@resource)
|
12
|
+
cond.expects(:wait).times(1)
|
12
13
|
|
13
14
|
eq.push(God::TimedEvent.new(0))
|
14
15
|
eq.push(God::TimedEvent.new(0.1))
|
data/test/test_email.rb
CHANGED
data/test/test_event_handler.rb
CHANGED
@@ -17,7 +17,7 @@ module God
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
class TestEventHandler < Test
|
20
|
+
class TestEventHandler < Minitest::Test
|
21
21
|
def setup
|
22
22
|
@h = God::EventHandler
|
23
23
|
end
|
@@ -74,7 +74,7 @@ end
|
|
74
74
|
|
75
75
|
# This doesn't currently work:
|
76
76
|
#
|
77
|
-
# class TestEventHandlerOperational < Test
|
77
|
+
# class TestEventHandlerOperational < Minitest::Test
|
78
78
|
# def test_operational
|
79
79
|
# God::EventHandler.start
|
80
80
|
# assert God::EventHandler.loaded?
|
data/test/test_god.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class TestGod < Test::Unit::TestCase
|
2
|
+
class TestGod < MiniTest::Test
|
4
3
|
def setup
|
5
4
|
God::Socket.stubs(:new).returns(true)
|
6
5
|
God.stubs(:setup).returns(true)
|
@@ -16,6 +15,10 @@ class TestGod < Test::Unit::TestCase
|
|
16
15
|
w.driver.thread.kill
|
17
16
|
end
|
18
17
|
end
|
18
|
+
God.reset
|
19
|
+
#Some of the tests in this file intentionally set pid_file_directory to an invalid value
|
20
|
+
#This can cause a later test failure since God will call abort if pid_file_directory is not writable
|
21
|
+
God.pid_file_directory = '~/.god/pids'
|
19
22
|
end
|
20
23
|
|
21
24
|
# applog
|
@@ -32,11 +35,10 @@ class TestGod < Test::Unit::TestCase
|
|
32
35
|
assert_equal Hash.new, God.watches
|
33
36
|
end
|
34
37
|
|
35
|
-
# init
|
38
|
+
# # init
|
36
39
|
|
37
40
|
def test_pid_file_directory_should_abort_if_called_after_watch
|
38
41
|
God.watch { |w| w.name = 'foo'; w.start = 'bar' }
|
39
|
-
|
40
42
|
assert_abort do
|
41
43
|
God.pid_file_directory = 'foo'
|
42
44
|
end
|
@@ -313,7 +315,7 @@ class TestGod < Test::Unit::TestCase
|
|
313
315
|
def test_control_should_raise_on_invalid_command
|
314
316
|
God.watch { |w| w.name = 'foo'; w.start = 'bar' }
|
315
317
|
|
316
|
-
|
318
|
+
assert_raises InvalidCommandError do
|
317
319
|
God.control('foo', 'invalid')
|
318
320
|
end
|
319
321
|
end
|
@@ -451,7 +453,7 @@ class TestGod < Test::Unit::TestCase
|
|
451
453
|
|
452
454
|
def test_running_log_should_raise_on_unknown_watch
|
453
455
|
God.internal_init
|
454
|
-
|
456
|
+
assert_raises(NoSuchWatchError) do
|
455
457
|
God.running_log('foo', Time.now)
|
456
458
|
end
|
457
459
|
end
|
@@ -662,7 +664,7 @@ class TestGod < Test::Unit::TestCase
|
|
662
664
|
end
|
663
665
|
|
664
666
|
|
665
|
-
# class TestGodOther < Test
|
667
|
+
# class TestGodOther < Minitest::Test
|
666
668
|
# def setup
|
667
669
|
# God::Socket.stubs(:new).returns(true)
|
668
670
|
# God.internal_init
|
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/helper'
|
|
2
2
|
|
3
3
|
if God::EventHandler.event_system == "kqueue"
|
4
4
|
|
5
|
-
class TestHandlersKqueueHandler < Test
|
5
|
+
class TestHandlersKqueueHandler < Minitest::Test
|
6
6
|
def test_register_process
|
7
7
|
KQueueHandler.expects(:monitor_process).with(1234, 2147483648)
|
8
8
|
KQueueHandler.register_process(1234, [:proc_exit])
|
data/test/test_hipchat.rb
CHANGED
data/test/test_jabber.rb
CHANGED
data/test/test_logger.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
|
-
class TestLogger < Test
|
3
|
+
class TestLogger < Minitest::Test
|
4
4
|
def setup
|
5
5
|
@log = God::Logger.new(StringIO.new('/dev/null'))
|
6
6
|
end
|
@@ -41,8 +41,8 @@ class TestLogger < Test::Unit::TestCase
|
|
41
41
|
|
42
42
|
out = @log.watch_log_since('foo', t2)
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
assert(/one/ !~ out)
|
45
|
+
assert(/two/ !~ out)
|
46
46
|
assert_match(/three/, out)
|
47
47
|
end
|
48
48
|
|
data/test/test_metric.rb
CHANGED
data/test/test_process.rb
CHANGED
@@ -12,7 +12,7 @@ module God
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
class TestProcessChild < Test
|
15
|
+
class TestProcessChild < Minitest::Test
|
16
16
|
def setup
|
17
17
|
God.internal_init
|
18
18
|
@p = God::Process.new
|
@@ -45,6 +45,9 @@ class TestProcessChild < Test::Unit::TestCase
|
|
45
45
|
@p.log = '/tmp/foo.log'
|
46
46
|
@p.uid = 'root'
|
47
47
|
|
48
|
+
::Process.stubs(:groups=)
|
49
|
+
::Process.stubs(:initgroups)
|
50
|
+
|
48
51
|
assert @p.valid?
|
49
52
|
end
|
50
53
|
|
@@ -142,13 +145,14 @@ end
|
|
142
145
|
#
|
143
146
|
###############################################################################
|
144
147
|
|
145
|
-
class TestProcessDaemon < Test
|
148
|
+
class TestProcessDaemon < Minitest::Test
|
146
149
|
def setup
|
147
150
|
God.internal_init
|
148
151
|
@p = God::Process.new
|
149
152
|
@p.name = 'foo'
|
150
153
|
@p.pid_file = 'blah.pid'
|
151
154
|
@p.stubs(:test).returns true # so we don't try to mkdir_p
|
155
|
+
God::System::Process.stubs(:fetch_system_poller).returns(God::System::PortablePoller)
|
152
156
|
Process.stubs(:detach) # because we stub fork
|
153
157
|
end
|
154
158
|
|
@@ -243,7 +247,7 @@ class TestProcessDaemon < Test::Unit::TestCase
|
|
243
247
|
|
244
248
|
assert @p.valid?
|
245
249
|
|
246
|
-
|
250
|
+
assert_raises NotImplementedError do
|
247
251
|
@p.call_action(:start)
|
248
252
|
end
|
249
253
|
end
|
data/test/test_prowl.rb
CHANGED