resurrected_god 0.14.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +559 -0
  3. data/README.md +9 -4
  4. data/bin/god +26 -28
  5. data/ext/god/extconf.rb +9 -9
  6. data/lib/god/behavior.rb +3 -5
  7. data/lib/god/behaviors/clean_pid_file.rb +4 -6
  8. data/lib/god/behaviors/clean_unix_socket.rb +4 -6
  9. data/lib/god/behaviors/notify_when_flapping.rb +13 -15
  10. data/lib/god/cli/command.rb +109 -89
  11. data/lib/god/cli/run.rb +51 -75
  12. data/lib/god/cli/version.rb +2 -4
  13. data/lib/god/condition.rb +12 -14
  14. data/lib/god/conditions/always.rb +3 -2
  15. data/lib/god/conditions/complex.rb +23 -24
  16. data/lib/god/conditions/cpu_usage.rb +12 -16
  17. data/lib/god/conditions/degrading_lambda.rb +15 -19
  18. data/lib/god/conditions/disk_usage.rb +7 -8
  19. data/lib/god/conditions/file_mtime.rb +3 -7
  20. data/lib/god/conditions/file_touched.rb +4 -5
  21. data/lib/god/conditions/flapping.rb +57 -62
  22. data/lib/god/conditions/http_response_code.rb +27 -32
  23. data/lib/god/conditions/lambda.rb +3 -5
  24. data/lib/god/conditions/memory_usage.rb +12 -16
  25. data/lib/god/conditions/process_exits.rb +12 -12
  26. data/lib/god/conditions/process_running.rb +8 -10
  27. data/lib/god/conditions/socket_responding.rb +23 -28
  28. data/lib/god/conditions/tries.rb +12 -14
  29. data/lib/god/configurable.rb +7 -10
  30. data/lib/god/contact.rb +41 -52
  31. data/lib/god/contacts/airbrake.rb +10 -12
  32. data/lib/god/contacts/campfire.rb +18 -20
  33. data/lib/god/contacts/email.rb +27 -28
  34. data/lib/god/contacts/prowl.rb +16 -17
  35. data/lib/god/contacts/scout.rb +2 -5
  36. data/lib/god/contacts/sensu.rb +15 -11
  37. data/lib/god/contacts/slack.rb +23 -33
  38. data/lib/god/contacts/statsd.rb +8 -8
  39. data/lib/god/contacts/twitter.rb +2 -2
  40. data/lib/god/contacts/webhook.rb +21 -24
  41. data/lib/god/driver.rb +12 -18
  42. data/lib/god/errors.rb +0 -2
  43. data/lib/god/event_handler.rb +40 -49
  44. data/lib/god/event_handlers/dummy_handler.rb +1 -1
  45. data/lib/god/event_handlers/kqueue_handler.rb +2 -2
  46. data/lib/god/event_handlers/netlink_handler.rb +1 -1
  47. data/lib/god/logger.rb +5 -13
  48. data/lib/god/metric.rb +13 -15
  49. data/lib/god/process.rb +93 -98
  50. data/lib/god/simple_logger.rb +13 -15
  51. data/lib/god/socket.rb +21 -23
  52. data/lib/god/sugar.rb +8 -8
  53. data/lib/god/sys_logger.rb +6 -8
  54. data/lib/god/system/portable_poller.rb +1 -9
  55. data/lib/god/system/process.rb +4 -6
  56. data/lib/god/system/slash_proc_poller.rb +17 -19
  57. data/lib/god/task.rb +110 -136
  58. data/lib/god/timeline.rb +2 -4
  59. data/lib/god/trigger.rb +7 -11
  60. data/lib/god/version.rb +1 -1
  61. data/lib/god/watch.rb +51 -57
  62. data/lib/god.rb +122 -148
  63. metadata +17 -370
  64. data/Announce.txt +0 -135
  65. data/Gemfile +0 -5
  66. data/Rakefile +0 -129
  67. data/doc/god.asciidoc +0 -1592
  68. data/doc/intro.asciidoc +0 -20
  69. data/ext/god/.gitignore +0 -5
  70. data/lib/god/compat19.rb +0 -33
  71. data/lib/god/contacts/hipchat.rb +0 -117
  72. data/lib/god/contacts/jabber.rb +0 -75
  73. data/test/configs/child_events/child_events.god +0 -44
  74. data/test/configs/child_events/simple_server.rb +0 -3
  75. data/test/configs/child_polls/child_polls.god +0 -37
  76. data/test/configs/child_polls/simple_server.rb +0 -12
  77. data/test/configs/complex/complex.god +0 -59
  78. data/test/configs/complex/simple_server.rb +0 -3
  79. data/test/configs/contact/contact.god +0 -118
  80. data/test/configs/contact/simple_server.rb +0 -3
  81. data/test/configs/daemon_events/daemon_events.god +0 -37
  82. data/test/configs/daemon_events/simple_server.rb +0 -8
  83. data/test/configs/daemon_events/simple_server_stop.rb +0 -11
  84. data/test/configs/daemon_polls/daemon_polls.god +0 -17
  85. data/test/configs/daemon_polls/simple_server.rb +0 -6
  86. data/test/configs/degrading_lambda/degrading_lambda.god +0 -31
  87. data/test/configs/degrading_lambda/tcp_server.rb +0 -15
  88. data/test/configs/keepalive/keepalive.god +0 -9
  89. data/test/configs/keepalive/keepalive.rb +0 -12
  90. data/test/configs/lifecycle/lifecycle.god +0 -25
  91. data/test/configs/matias/matias.god +0 -50
  92. data/test/configs/real.rb +0 -59
  93. data/test/configs/running_load/running_load.god +0 -16
  94. data/test/configs/stop_options/simple_server.rb +0 -12
  95. data/test/configs/stop_options/stop_options.god +0 -39
  96. data/test/configs/stress/simple_server.rb +0 -3
  97. data/test/configs/stress/stress.god +0 -15
  98. data/test/configs/task/logs/.placeholder +0 -0
  99. data/test/configs/task/task.god +0 -26
  100. data/test/configs/test.rb +0 -61
  101. data/test/configs/usr1_trapper.rb +0 -10
  102. data/test/helper.rb +0 -172
  103. data/test/suite.rb +0 -6
  104. data/test/test_airbrake.rb +0 -14
  105. data/test/test_behavior.rb +0 -18
  106. data/test/test_campfire.rb +0 -22
  107. data/test/test_condition.rb +0 -52
  108. data/test/test_conditions_disk_usage.rb +0 -50
  109. data/test/test_conditions_http_response_code.rb +0 -109
  110. data/test/test_conditions_process_running.rb +0 -40
  111. data/test/test_conditions_socket_responding.rb +0 -176
  112. data/test/test_conditions_tries.rb +0 -67
  113. data/test/test_contact.rb +0 -109
  114. data/test/test_driver.rb +0 -26
  115. data/test/test_email.rb +0 -34
  116. data/test/test_event_handler.rb +0 -82
  117. data/test/test_god.rb +0 -710
  118. data/test/test_god_system.rb +0 -201
  119. data/test/test_handlers_kqueue_handler.rb +0 -16
  120. data/test/test_hipchat.rb +0 -23
  121. data/test/test_jabber.rb +0 -29
  122. data/test/test_logger.rb +0 -55
  123. data/test/test_metric.rb +0 -74
  124. data/test/test_process.rb +0 -263
  125. data/test/test_prowl.rb +0 -15
  126. data/test/test_registry.rb +0 -15
  127. data/test/test_sensu.rb +0 -11
  128. data/test/test_slack.rb +0 -57
  129. data/test/test_socket.rb +0 -34
  130. data/test/test_statsd.rb +0 -22
  131. data/test/test_sugar.rb +0 -42
  132. data/test/test_system_portable_poller.rb +0 -17
  133. data/test/test_system_process.rb +0 -30
  134. data/test/test_task.rb +0 -246
  135. data/test/test_timeline.rb +0 -37
  136. data/test/test_trigger.rb +0 -63
  137. data/test/test_watch.rb +0 -286
  138. data/test/test_webhook.rb +0 -22
@@ -1,109 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestHttpResponseCode < Minitest::Test
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
- 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
- assert !c.valid?
37
- end
38
-
39
- # test
40
-
41
- def test_test_should_return_false_if_code_is_is_set_to_200_but_response_is_500
42
- c = valid_condition
43
- Net::HTTP.any_instance.expects(:start).yields(mock(:read_timeout= => nil, :get => mock(:code => 500)))
44
- assert_equal false, c.test
45
- end
46
-
47
- def test_test_should_return_false_if_code_is_not_is_set_to_200_and_response_is_200
48
- c = valid_condition do |cc|
49
- cc.code_is = nil
50
- cc.code_is_not = [200]
51
- end
52
- Net::HTTP.any_instance.expects(:start).yields(mock(:read_timeout= => nil, :get => mock(:code => 200)))
53
- assert_equal false, c.test
54
- end
55
-
56
- def test_test_should_return_true_if_code_is_is_set_to_200_and_response_is_200
57
- c = valid_condition
58
- Net::HTTP.any_instance.expects(:start).yields(mock(:read_timeout= => nil, :get => mock(:code => 200)))
59
- assert_equal true, c.test
60
- end
61
-
62
- def test_test_should_return_false_if_code_is_not_is_set_to_200_but_response_is_500
63
- c = valid_condition do |cc|
64
- cc.code_is = nil
65
- cc.code_is_not = [200]
66
- end
67
- Net::HTTP.any_instance.expects(:start).yields(mock(:read_timeout= => nil, :get => mock(:code => 500)))
68
- assert_equal true, c.test
69
- end
70
-
71
- def test_test_should_return_false_if_code_is_is_set_to_200_but_response_times_out
72
- c = valid_condition
73
- Net::HTTP.any_instance.expects(:start).raises(Timeout::Error, '')
74
- assert_equal false, c.test
75
- end
76
-
77
- def test_test_should_return_true_if_code_is_not_is_set_to_200_and_response_times_out
78
- c = valid_condition do |cc|
79
- cc.code_is = nil
80
- cc.code_is_not = [200]
81
- end
82
- Net::HTTP.any_instance.expects(:start).raises(Timeout::Error, '')
83
- assert_equal true, c.test
84
- end
85
-
86
- def test_test_should_return_false_if_code_is_is_set_to_200_but_cant_connect
87
- c = valid_condition
88
- Net::HTTP.any_instance.expects(:start).raises(Errno::ECONNREFUSED, '')
89
- assert_equal false, c.test
90
- end
91
-
92
- def test_test_should_return_true_if_code_is_not_is_set_to_200_and_cant_connect
93
- c = valid_condition do |cc|
94
- cc.code_is = nil
95
- cc.code_is_not = [200]
96
- end
97
- Net::HTTP.any_instance.expects(:start).raises(Errno::ECONNREFUSED, '')
98
- assert_equal true, c.test
99
- end
100
-
101
- def test_test_should_return_true_if_code_is_is_set_to_200_and_response_is_200_twice_for_times_two_of_two
102
- c = valid_condition do |cc|
103
- cc.times = [2, 2]
104
- end
105
- Net::HTTP.any_instance.expects(:start).yields(stub(:read_timeout= => nil, :get => stub(:code => 200))).times(2)
106
- assert_equal false, c.test
107
- assert_equal true, c.test
108
- end
109
- end
@@ -1,40 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestConditionsProcessRunning < Minitest::Test
4
- def test_missing_pid_file_returns_opposite
5
- [true, false].each do |r|
6
- c = Conditions::ProcessRunning.new
7
- c.running = r
8
- c.stubs(:watch).returns(stub(:pid => 99999999, :name => 'foo'))
9
- assert_equal !r, c.test
10
- end
11
- end
12
-
13
- def test_not_running_returns_opposite
14
- [true, false].each do |r|
15
- c = Conditions::ProcessRunning.new
16
- c.running = r
17
-
18
- File.stubs(:exist?).returns(true)
19
- c.stubs(:watch).returns(stub(:pid => 123))
20
- File.stubs(:read).returns('5')
21
- System::Process.any_instance.stubs(:exists?).returns(false)
22
-
23
- assert_equal !r, c.test
24
- end
25
- end
26
-
27
- def test_running_returns_same
28
- [true, false].each do |r|
29
- c = Conditions::ProcessRunning.new
30
- c.running = r
31
-
32
- File.stubs(:exist?).returns(true)
33
- c.stubs(:watch).returns(stub(:pid => 123))
34
- File.stubs(:read).returns('5')
35
- System::Process.any_instance.stubs(:exists?).returns(true)
36
-
37
- assert_equal r, c.test
38
- end
39
- end
40
- end
@@ -1,176 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestConditionsSocketResponding < Minitest::Test
4
- # valid?
5
-
6
- def test_valid_should_return_false_if_no_options_set
7
- c = Conditions::SocketResponding.new
8
- c.watch = stub(:name => 'foo')
9
- assert_equal false, c.valid?
10
-
11
- end
12
-
13
- def test_valid_should_return_true_if_required_options_set_for_default
14
- c = Conditions::SocketResponding.new
15
- c.port = 443
16
- assert_equal true, c.valid?
17
- end
18
-
19
- def test_valid_should_return_true_if_required_options_set_for_tcp
20
- c = Conditions::SocketResponding.new
21
- c.family = 'tcp'
22
- c.port = 443
23
- assert_equal true, c.valid?
24
- end
25
-
26
- def test_valid_should_return_true_if_required_options_set_for_unix
27
- c = Conditions::SocketResponding.new
28
- c.path = 'some-path'
29
- c.family = 'unix'
30
- assert_equal true, c.valid?
31
- end
32
-
33
- def test_valid_should_return_true_if_family_is_tcp
34
- c = Conditions::SocketResponding.new
35
- c.port = 443
36
- c.family = 'tcp'
37
- assert_equal true, c.valid?
38
- end
39
-
40
- def test_valid_should_return_true_if_family_is_unix
41
- c = Conditions::SocketResponding.new
42
- c.path = 'some-path'
43
- c.family = 'unix'
44
- c.watch = stub(:name => 'foo')
45
- assert_equal true, c.valid?
46
- end
47
-
48
- # socket method
49
- def test_socket_should_return_127_0_0_1_for_default_addr
50
- c = Conditions::SocketResponding.new
51
- c.socket = 'tcp:443'
52
- assert_equal c.addr, '127.0.0.1'
53
- end
54
-
55
- def test_socket_should_set_properties_for_tcp
56
- c = Conditions::SocketResponding.new
57
- c.socket = 'tcp:127.0.0.1:443'
58
- assert_equal c.family, 'tcp'
59
- assert_equal c.addr, '127.0.0.1'
60
- assert_equal c.port, 443
61
- assert_equal c.responding, false
62
- # path should not be set for tcp sockets
63
- assert_equal c.path, nil
64
- end
65
-
66
- def test_socket_should_set_properties_for_unix
67
- c = Conditions::SocketResponding.new
68
- c.socket = 'unix:/tmp/process.sock'
69
- assert_equal c.family, 'unix'
70
- assert_equal c.path, '/tmp/process.sock'
71
- assert_equal c.responding, false
72
- # path should not be set for unix domain sockets
73
- assert_equal c.port, 0
74
- end
75
-
76
- # test : responding = false
77
-
78
- def test_test_tcp_should_return_false_if_socket_is_listening
79
- c = Conditions::SocketResponding.new
80
- c.prepare
81
-
82
- TCPSocket.expects(:new).returns(0)
83
- assert_equal false, c.test
84
- end
85
-
86
- def test_test_tcp_should_return_true_if_no_socket_is_listening
87
- c = Conditions::SocketResponding.new
88
- c.prepare
89
-
90
- TCPSocket.expects(:new).returns(nil)
91
- assert_equal true, c.test
92
- end
93
-
94
- def test_test_unix_should_return_false_if_socket_is_listening
95
- c = Conditions::SocketResponding.new
96
- c.socket = 'unix:/some/path'
97
-
98
- c.prepare
99
- UNIXSocket.expects(:new).returns(0)
100
- assert_equal false, c.test
101
- end
102
-
103
- def test_test_unix_should_return_true_if_no_socket_is_listening
104
-
105
- c = Conditions::SocketResponding.new
106
- c.socket = 'unix:/some/path'
107
- c.prepare
108
-
109
- UNIXSocket.expects(:new).returns(nil)
110
- assert_equal true, c.test
111
- end
112
-
113
- def test_test_unix_should_return_true_if_socket_is_listening_2_times
114
-
115
- c = Conditions::SocketResponding.new
116
- c.socket = 'unix:/some/path'
117
- c.times = [2, 2]
118
- c.prepare
119
-
120
- UNIXSocket.expects(:new).returns(nil).times(2)
121
- assert_equal false, c.test
122
- assert_equal true, c.test
123
- end
124
-
125
- # test : responding = true
126
-
127
- def test_test_tcp_should_return_true_if_socket_is_listening_with_responding_true
128
- c = Conditions::SocketResponding.new
129
- c.responding = true
130
- c.prepare
131
-
132
- TCPSocket.expects(:new).returns(0)
133
- assert_equal true, c.test
134
- end
135
-
136
- def test_test_tcp_should_return_false_if_no_socket_is_listening_with_responding_true
137
- c = Conditions::SocketResponding.new
138
- c.responding = true
139
- c.prepare
140
-
141
- TCPSocket.expects(:new).returns(nil)
142
- assert_equal false, c.test
143
- end
144
-
145
- def test_test_unix_should_return_true_if_socket_is_listening_with_responding_true
146
- c = Conditions::SocketResponding.new
147
- c.responding = true
148
- c.socket = 'unix:/some/path'
149
-
150
- c.prepare
151
- UNIXSocket.expects(:new).returns(0)
152
- assert_equal true, c.test
153
- end
154
-
155
- def test_test_unix_should_return_false_if_no_socket_is_listening_with_responding_true
156
- c = Conditions::SocketResponding.new
157
- c.socket = 'unix:/some/path'
158
- c.responding = true
159
- c.prepare
160
-
161
- UNIXSocket.expects(:new).returns(nil)
162
- assert_equal false, c.test
163
- end
164
-
165
- def test_test_unix_should_return_false_if_socket_is_listening_2_times_with_responding_true
166
- c = Conditions::SocketResponding.new
167
- c.socket = 'unix:/some/path'
168
- c.responding = true
169
- c.times = [2, 2]
170
- c.prepare
171
-
172
- UNIXSocket.expects(:new).returns(nil).times(2)
173
- assert_equal false, c.test
174
- assert_equal false, c.test
175
- end
176
- end
@@ -1,67 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestConditionsTries < Minitest::Test
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
- assert !c.valid?
10
- end
11
- end
12
-
13
-
14
- class TestConditionsTries < Minitest::Test
15
- def setup
16
- @c = Conditions::Tries.new
17
- @c.times = 3
18
- @c.prepare
19
- end
20
-
21
- # prepare
22
-
23
- def test_prepare_should_create_timeline
24
- assert_equal 3, @c.instance_variable_get(:@timeline).instance_variable_get(:@max_size)
25
- end
26
-
27
- # test
28
-
29
- def test_test_should_return_true_if_called_three_times_within_one_second
30
- assert !@c.test
31
- assert !@c.test
32
- assert @c.test
33
- end
34
-
35
- # reset
36
-
37
- def test_test_should_return_false_on_fourth_call_if_called_three_times_within_one_second
38
- 3.times { @c.test }
39
- @c.reset
40
- assert !@c.test
41
- end
42
- end
43
-
44
-
45
- class TestConditionsTriesWithin < Minitest::Test
46
- def setup
47
- @c = Conditions::Tries.new
48
- @c.times = 3
49
- @c.within = 1.seconds
50
- @c.prepare
51
- end
52
-
53
- # test
54
-
55
- def test_test_should_return_true_if_called_three_times_within_one_second
56
- assert !@c.test
57
- assert !@c.test
58
- assert @c.test
59
- end
60
-
61
- def test_test_should_return_false_if_called_three_times_within_two_seconds
62
- assert !@c.test
63
- assert !@c.test
64
- assert sleep(1.1)
65
- assert !@c.test
66
- end
67
- end
data/test/test_contact.rb DELETED
@@ -1,109 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestContact < Minitest::Test
4
- def test_exists
5
- God::Contact
6
- end
7
-
8
- # generate
9
-
10
- def test_generate_should_raise_on_invalid_kind
11
- assert_raises(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_raises 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_raises 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_raises 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_raises 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_raises 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_raises ArgumentError do
98
- Contact.normalize(input)
99
- end
100
- end
101
-
102
- # notify
103
-
104
- def test_notify_should_be_abstract
105
- assert_raises(AbstractMethodNotOverriddenError) do
106
- Contact.new.notify(:a, :b, :c, :d, :e)
107
- end
108
- end
109
- end
data/test/test_driver.rb DELETED
@@ -1,26 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestDriver < Minitest::Test
4
- def setup
5
-
6
- end
7
-
8
- def test_push_pop_wait
9
-
10
- eq = God::DriverEventQueue.new
11
- cond = eq.instance_variable_get(:@resource)
12
- cond.expects(:wait).times(1)
13
-
14
- eq.push(God::TimedEvent.new(0))
15
- eq.push(God::TimedEvent.new(0.1))
16
- t = Thread.new do
17
- # This pop will see an event immediately available, so no wait.
18
- assert_equal TimedEvent, eq.pop.class
19
-
20
- # This pop will happen before the next event is due, so wait.
21
- assert_equal TimedEvent, eq.pop.class
22
- end
23
-
24
- t.join
25
- end
26
- end
data/test/test_email.rb DELETED
@@ -1,34 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestEmail < Minitest::Test
4
- def setup
5
- God::Contacts::Email.to_email = 'dev@example.com'
6
- God::Contacts::Email.from_email = 'god@example.com'
7
- @email = God::Contacts::Email.new
8
- end
9
-
10
- def test_validity_delivery
11
- @email.delivery_method = :brainwaves
12
- assert_equal false, @email.valid?
13
- end
14
-
15
- def test_smtp_delivery_method_for_notify
16
- @email.delivery_method = :smtp
17
-
18
- God::Contacts::Email.any_instance.expects(:notify_sendmail).never
19
- God::Contacts::Email.any_instance.expects(:notify_smtp).once.returns(nil)
20
-
21
- @email.notify('msg', Time.now, 'prio', 'cat', 'host')
22
- assert_equal "sent email to dev@example.com via smtp", @email.info
23
- end
24
-
25
- def test_sendmail_delivery_method_for_notify
26
- @email.delivery_method = :sendmail
27
-
28
- God::Contacts::Email.any_instance.expects(:notify_smtp).never
29
- God::Contacts::Email.any_instance.expects(:notify_sendmail).once.returns(nil)
30
-
31
- @email.notify('msg', Time.now, 'prio', 'cat', 'host')
32
- assert_equal "sent email to dev@example.com via sendmail", @email.info
33
- end
34
- end
@@ -1,82 +0,0 @@
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 < Minitest::Test
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
- # This doesn't currently work:
76
- #
77
- # class TestEventHandlerOperational < Minitest::Test
78
- # def test_operational
79
- # God::EventHandler.start
80
- # assert God::EventHandler.loaded?
81
- # end
82
- # end