strobemonkey-god 0.7.13
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 +289 -0
- data/Manifest.txt +114 -0
- data/README.txt +59 -0
- data/Rakefile +35 -0
- data/bin/god +128 -0
- data/examples/events.god +84 -0
- data/examples/gravatar.god +54 -0
- data/examples/single.god +66 -0
- data/ext/god/extconf.rb +55 -0
- data/ext/god/kqueue_handler.c +123 -0
- data/ext/god/netlink_handler.c +167 -0
- data/init/god +42 -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 +229 -0
- data/lib/god/cli/run.rb +176 -0
- data/lib/god/cli/version.rb +23 -0
- data/lib/god/condition.rb +96 -0
- data/lib/god/conditions/always.rb +23 -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 +27 -0
- data/lib/god/conditions/file_mtime.rb +28 -0
- data/lib/god/conditions/flapping.rb +128 -0
- data/lib/god/conditions/http_response_code.rb +168 -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 +72 -0
- data/lib/god/conditions/process_running.rb +74 -0
- data/lib/god/conditions/tries.rb +44 -0
- data/lib/god/configurable.rb +57 -0
- data/lib/god/contact.rb +106 -0
- data/lib/god/contacts/campfire.rb +82 -0
- data/lib/god/contacts/email.rb +95 -0
- data/lib/god/contacts/jabber.rb +65 -0
- data/lib/god/contacts/twitter.rb +39 -0
- data/lib/god/contacts/webhook.rb +47 -0
- data/lib/god/dependency_graph.rb +41 -0
- data/lib/god/diagnostics.rb +37 -0
- data/lib/god/driver.rb +206 -0
- data/lib/god/errors.rb +24 -0
- data/lib/god/event_handler.rb +111 -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 +120 -0
- data/lib/god/metric.rb +59 -0
- data/lib/god/process.rb +341 -0
- data/lib/god/registry.rb +32 -0
- data/lib/god/simple_logger.rb +53 -0
- data/lib/god/socket.rb +96 -0
- data/lib/god/sugar.rb +47 -0
- data/lib/god/system/portable_poller.rb +42 -0
- data/lib/god/system/process.rb +42 -0
- data/lib/god/system/slash_proc_poller.rb +92 -0
- data/lib/god/task.rb +491 -0
- data/lib/god/timeline.rb +25 -0
- data/lib/god/trigger.rb +43 -0
- data/lib/god/watch.rb +183 -0
- data/lib/god.rb +667 -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 +84 -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/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/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/helper.rb +151 -0
- data/test/suite.rb +6 -0
- data/test/test_behavior.rb +21 -0
- data/test/test_campfire.rb +41 -0
- data/test/test_condition.rb +50 -0
- data/test/test_conditions_disk_usage.rb +56 -0
- data/test/test_conditions_http_response_code.rb +109 -0
- data/test/test_conditions_process_running.rb +44 -0
- data/test/test_conditions_tries.rb +67 -0
- data/test/test_contact.rb +109 -0
- data/test/test_dependency_graph.rb +62 -0
- data/test/test_driver.rb +11 -0
- data/test/test_email.rb +45 -0
- data/test/test_event_handler.rb +80 -0
- data/test/test_god.rb +598 -0
- data/test/test_handlers_kqueue_handler.rb +16 -0
- data/test/test_logger.rb +63 -0
- data/test/test_metric.rb +72 -0
- data/test/test_process.rb +246 -0
- data/test/test_registry.rb +15 -0
- data/test/test_socket.rb +42 -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 +262 -0
- data/test/test_timeline.rb +37 -0
- data/test/test_trigger.rb +59 -0
- data/test/test_watch.rb +279 -0
- metadata +193 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
|
2
|
+
|
|
3
|
+
class TestDependencyGraph < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@dg = DependencyGraph.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# new
|
|
9
|
+
|
|
10
|
+
def test_new_should_accept_zero_arguments
|
|
11
|
+
assert @dg.instance_of?(DependencyGraph)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# add
|
|
15
|
+
|
|
16
|
+
def test_add_should_create_and_store_two_new_nodes
|
|
17
|
+
@dg.add('foo', 'bar')
|
|
18
|
+
assert_equal 2, @dg.nodes.size
|
|
19
|
+
assert @dg.nodes['foo'].instance_of?(DependencyGraph::Node)
|
|
20
|
+
assert @dg.nodes['bar'].instance_of?(DependencyGraph::Node)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_add_should_record_dependency
|
|
24
|
+
@dg.add('foo', 'bar')
|
|
25
|
+
assert_equal 1, @dg.nodes['foo'].dependencies.size
|
|
26
|
+
assert_equal @dg.nodes['bar'], @dg.nodes['foo'].dependencies.first
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_add_should_ignore_dups
|
|
30
|
+
@dg.add('foo', 'bar')
|
|
31
|
+
@dg.add('foo', 'bar')
|
|
32
|
+
assert_equal 2, @dg.nodes.size
|
|
33
|
+
assert_equal 1, @dg.nodes['foo'].dependencies.size
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class TestDependencyGraphNode < Test::Unit::TestCase
|
|
39
|
+
def setup
|
|
40
|
+
@foo = DependencyGraph::Node.new('foo')
|
|
41
|
+
@bar = DependencyGraph::Node.new('bar')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# new
|
|
45
|
+
|
|
46
|
+
def test_new_should_accept_zero_arguments
|
|
47
|
+
assert @foo.instance_of?(DependencyGraph::Node)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# add
|
|
51
|
+
|
|
52
|
+
def test_add_should_store_node_as_dependency
|
|
53
|
+
@foo.add(@bar)
|
|
54
|
+
assert_equal 1, @foo.dependencies.size
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# has_node?
|
|
58
|
+
|
|
59
|
+
def test_has_node
|
|
60
|
+
assert @foo.has_node?(@foo)
|
|
61
|
+
end
|
|
62
|
+
end
|
data/test/test_driver.rb
ADDED
data/test/test_email.rb
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
|
2
|
+
|
|
3
|
+
class TestEmail < Test::Unit::TestCase
|
|
4
|
+
def test_exists
|
|
5
|
+
God::Contacts::Email
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_unknown_delivery_method_for_notify
|
|
9
|
+
assert_nothing_raised do
|
|
10
|
+
God::Contacts::Email.any_instance.expects(:notify_smtp).never
|
|
11
|
+
God::Contacts::Email.any_instance.expects(:notify_sendmail).never
|
|
12
|
+
God::Contacts::Email.delivery_method = :foo_protocol
|
|
13
|
+
LOG.expects(:log).times(2)
|
|
14
|
+
|
|
15
|
+
g = God::Contacts::Email.new
|
|
16
|
+
g.notify(:a, :b, :c, :d, :e)
|
|
17
|
+
assert_nil g.info
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_smtp_delivery_method_for_notify
|
|
22
|
+
assert_nothing_raised do
|
|
23
|
+
God::Contacts::Email.any_instance.expects(:notify_sendmail).never
|
|
24
|
+
God::Contacts::Email.any_instance.expects(:notify_smtp).once.returns(nil)
|
|
25
|
+
God::Contacts::Email.delivery_method = :smtp
|
|
26
|
+
g = God::Contacts::Email.new
|
|
27
|
+
g.email = 'joe@example.com'
|
|
28
|
+
g.notify(:a, :b, :c, :d, :e)
|
|
29
|
+
assert_equal "sent email to joe@example.com", g.info
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_sendmail_delivery_method_for_notify
|
|
34
|
+
assert_nothing_raised do
|
|
35
|
+
God::Contacts::Email.any_instance.expects(:notify_smtp).never
|
|
36
|
+
God::Contacts::Email.any_instance.expects(:notify_sendmail).once.returns(nil)
|
|
37
|
+
God::Contacts::Email.delivery_method = :sendmail
|
|
38
|
+
g = God::Contacts::Email.new
|
|
39
|
+
g.email = 'joe@example.com'
|
|
40
|
+
g.notify(:a, :b, :c, :d, :e)
|
|
41
|
+
assert_equal "sent email to joe@example.com", g.info
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
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 < Test::Unit::TestCase
|
|
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
|
+
class TestEventHandlerOperational < Test::Unit::TestCase
|
|
76
|
+
def test_operational
|
|
77
|
+
God::EventHandler.start
|
|
78
|
+
assert God::EventHandler.loaded?
|
|
79
|
+
end
|
|
80
|
+
end
|