mcproc 2016.2.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Announce.txt +135 -0
- data/Gemfile +9 -0
- data/History.txt +469 -0
- data/LICENSE +22 -0
- data/README.md +37 -0
- data/Rakefile +185 -0
- data/TODO.md +37 -0
- data/bin/mcproc +134 -0
- data/doc/intro.asciidoc +20 -0
- data/doc/mcproc.asciidoc +1592 -0
- data/ext/god/.gitignore +5 -0
- data/ext/god/extconf.rb +56 -0
- data/ext/god/kqueue_handler.c +133 -0
- data/ext/god/netlink_handler.c +182 -0
- data/lib/god.rb +780 -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 +268 -0
- data/lib/god/cli/run.rb +170 -0
- data/lib/god/cli/version.rb +23 -0
- data/lib/god/compat19.rb +33 -0
- data/lib/god/condition.rb +96 -0
- data/lib/god/conditions/always.rb +36 -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 +32 -0
- data/lib/god/conditions/file_mtime.rb +28 -0
- data/lib/god/conditions/file_touched.rb +44 -0
- data/lib/god/conditions/flapping.rb +128 -0
- data/lib/god/conditions/http_response_code.rb +184 -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 +66 -0
- data/lib/god/conditions/process_running.rb +63 -0
- data/lib/god/conditions/socket_responding.rb +142 -0
- data/lib/god/conditions/tries.rb +44 -0
- data/lib/god/configurable.rb +57 -0
- data/lib/god/contact.rb +114 -0
- data/lib/god/contacts/airbrake.rb +44 -0
- data/lib/god/contacts/campfire.rb +121 -0
- data/lib/god/contacts/email.rb +130 -0
- data/lib/god/contacts/hipchat.rb +117 -0
- data/lib/god/contacts/jabber.rb +75 -0
- data/lib/god/contacts/prowl.rb +57 -0
- data/lib/god/contacts/scout.rb +55 -0
- data/lib/god/contacts/sensu.rb +59 -0
- data/lib/god/contacts/slack.rb +98 -0
- data/lib/god/contacts/statsd.rb +46 -0
- data/lib/god/contacts/twitter.rb +51 -0
- data/lib/god/contacts/webhook.rb +74 -0
- data/lib/god/driver.rb +238 -0
- data/lib/god/errors.rb +24 -0
- data/lib/god/event_handler.rb +112 -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 +109 -0
- data/lib/god/metric.rb +87 -0
- data/lib/god/process.rb +381 -0
- data/lib/god/registry.rb +32 -0
- data/lib/god/simple_logger.rb +59 -0
- data/lib/god/socket.rb +113 -0
- data/lib/god/sugar.rb +62 -0
- data/lib/god/sys_logger.rb +45 -0
- data/lib/god/system/portable_poller.rb +42 -0
- data/lib/god/system/process.rb +50 -0
- data/lib/god/system/slash_proc_poller.rb +92 -0
- data/lib/god/task.rb +552 -0
- data/lib/god/timeline.rb +25 -0
- data/lib/god/trigger.rb +43 -0
- data/lib/god/watch.rb +340 -0
- data/mcproc.gemspec +192 -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 +118 -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/keepalive/keepalive.god +9 -0
- data/test/configs/keepalive/keepalive.rb +12 -0
- data/test/configs/lifecycle/lifecycle.god +25 -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/stop_options/simple_server.rb +12 -0
- data/test/configs/stop_options/stop_options.god +39 -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/configs/usr1_trapper.rb +10 -0
- data/test/helper.rb +172 -0
- data/test/suite.rb +6 -0
- data/test/test_airbrake.rb +14 -0
- data/test/test_behavior.rb +18 -0
- data/test/test_campfire.rb +22 -0
- data/test/test_condition.rb +52 -0
- data/test/test_conditions_disk_usage.rb +50 -0
- data/test/test_conditions_http_response_code.rb +109 -0
- data/test/test_conditions_process_running.rb +40 -0
- data/test/test_conditions_socket_responding.rb +176 -0
- data/test/test_conditions_tries.rb +67 -0
- data/test/test_contact.rb +109 -0
- data/test/test_driver.rb +26 -0
- data/test/test_email.rb +34 -0
- data/test/test_event_handler.rb +82 -0
- data/test/test_god.rb +710 -0
- data/test/test_god_system.rb +201 -0
- data/test/test_handlers_kqueue_handler.rb +16 -0
- data/test/test_hipchat.rb +23 -0
- data/test/test_jabber.rb +29 -0
- data/test/test_logger.rb +55 -0
- data/test/test_metric.rb +74 -0
- data/test/test_process.rb +263 -0
- data/test/test_prowl.rb +15 -0
- data/test/test_registry.rb +15 -0
- data/test/test_sensu.rb +11 -0
- data/test/test_slack.rb +57 -0
- data/test/test_socket.rb +34 -0
- data/test/test_statsd.rb +22 -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 +246 -0
- data/test/test_timeline.rb +37 -0
- data/test/test_trigger.rb +63 -0
- data/test/test_watch.rb +286 -0
- data/test/test_webhook.rb +22 -0
- metadata +475 -0
data/test/suite.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/helper'
|
3
|
+
|
4
|
+
class TestAirbrake < Minitest::Test
|
5
|
+
def test_notify
|
6
|
+
airbrake = God::Contacts::Airbrake.new
|
7
|
+
airbrake.apikey = "put_your_apikey_here"
|
8
|
+
airbrake.name = "Airbrake"
|
9
|
+
|
10
|
+
Airbrake.expects(:notify).returns "123"
|
11
|
+
|
12
|
+
airbrake.notify("Test message for airbrake", Time.now, "airbrake priority", "airbrake category", "")
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestBehavior < Minitest::Test
|
4
|
+
def test_generate_should_return_an_object_corresponding_to_the_given_type
|
5
|
+
assert_equal Behaviors::FakeBehavior, Behavior.generate(:fake_behavior, nil).class
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_generate_should_raise_on_invalid_type
|
9
|
+
assert_raises NoSuchBehaviorError do
|
10
|
+
Behavior.generate(:foo, nil)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_complain
|
15
|
+
SysLogger.expects(:log).with(:error, 'foo')
|
16
|
+
assert !Behavior.allocate.bypass.complain('foo')
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestCampfire < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@campfire = God::Contacts::Campfire.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_exists
|
9
|
+
God::Contacts::Campfire
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_notify
|
13
|
+
@campfire.subdomain = 'github'
|
14
|
+
@campfire.token = 'abc'
|
15
|
+
@campfire.room = 'danger'
|
16
|
+
|
17
|
+
time = Time.now
|
18
|
+
body = "[#{time.strftime('%H:%M:%S')}] host - msg"
|
19
|
+
Marshmallow::Connection.any_instance.expects(:speak).with('danger', body)
|
20
|
+
@campfire.notify('msg', time, 'prio', 'cat', 'host')
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class BadlyImplementedCondition < PollCondition
|
4
|
+
end
|
5
|
+
|
6
|
+
class TestCondition < Minitest::Test
|
7
|
+
|
8
|
+
# generate
|
9
|
+
|
10
|
+
def test_generate_should_return_an_object_corresponding_to_the_given_type
|
11
|
+
assert_equal Conditions::ProcessRunning, Condition.generate(:process_running, nil).class
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_generate_should_raise_on_invalid_type
|
15
|
+
assert_raises NoSuchConditionError do
|
16
|
+
Condition.generate(:foo, nil)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_generate_should_abort_on_event_condition_without_loaded_event_system
|
21
|
+
God::EventHandler.stubs(:operational?).returns(false)
|
22
|
+
assert_abort do
|
23
|
+
God::EventHandler.start
|
24
|
+
Condition.generate(:process_exits, nil).class
|
25
|
+
end
|
26
|
+
ensure
|
27
|
+
God::EventHandler.stop
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_generate_should_return_a_good_error_message_for_invalid_types
|
31
|
+
emsg = "No Condition found with the class name God::Conditions::FooBar"
|
32
|
+
rmsg = nil
|
33
|
+
|
34
|
+
begin
|
35
|
+
Condition.generate(:foo_bar, nil)
|
36
|
+
rescue => e
|
37
|
+
rmsg = e.message
|
38
|
+
end
|
39
|
+
|
40
|
+
assert_equal emsg, rmsg
|
41
|
+
end
|
42
|
+
|
43
|
+
# test
|
44
|
+
|
45
|
+
def test_test_should_raise_if_not_defined_in_subclass
|
46
|
+
c = BadlyImplementedCondition.new
|
47
|
+
|
48
|
+
assert_raises AbstractMethodNotOverriddenError do
|
49
|
+
c.test
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestConditionsDiskUsage < Minitest::Test
|
4
|
+
# valid?
|
5
|
+
|
6
|
+
def test_valid_should_return_false_if_no_above_given
|
7
|
+
c = Conditions::DiskUsage.new
|
8
|
+
c.mount_point = '/'
|
9
|
+
c.watch = stub(:name => 'foo')
|
10
|
+
assert_equal false, c.valid?
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_valid_should_return_false_if_no_mount_point_given
|
14
|
+
c = Conditions::DiskUsage.new
|
15
|
+
c.above = 90
|
16
|
+
c.watch = stub(:name => 'foo')
|
17
|
+
assert_equal false, c.valid?
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_valid_should_return_true_if_required_options_all_set
|
21
|
+
c = Conditions::DiskUsage.new
|
22
|
+
c.above = 90
|
23
|
+
c.mount_point = '/'
|
24
|
+
c.watch = stub(:name => 'foo')
|
25
|
+
|
26
|
+
assert_equal true, c.valid?
|
27
|
+
end
|
28
|
+
|
29
|
+
# test
|
30
|
+
|
31
|
+
def test_test_should_return_true_if_above_limit
|
32
|
+
c = Conditions::DiskUsage.new
|
33
|
+
c.above = 90
|
34
|
+
c.mount_point = '/'
|
35
|
+
|
36
|
+
c.expects(:`).returns('91')
|
37
|
+
|
38
|
+
assert_equal true, c.test
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_test_should_return_false_if_below_limit
|
42
|
+
c = Conditions::DiskUsage.new
|
43
|
+
c.above = 90
|
44
|
+
c.mount_point = '/'
|
45
|
+
|
46
|
+
c.expects(:`).returns('90')
|
47
|
+
|
48
|
+
assert_equal false, c.test
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,109 @@
|
|
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
|
@@ -0,0 +1,40 @@
|
|
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
|
@@ -0,0 +1,176 @@
|
|
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
|