god 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Announce.txt +6 -6
- data/Gemfile +2 -0
- data/History.txt +19 -2
- data/{README.txt → LICENSE} +0 -37
- data/README.md +31 -0
- data/Rakefile +80 -38
- data/bin/god +21 -21
- data/doc/god.asciidoc +1487 -0
- data/doc/intro.asciidoc +20 -0
- data/ext/god/extconf.rb +3 -3
- data/ext/god/kqueue_handler.c +18 -18
- data/ext/god/netlink_handler.c +31 -31
- data/god.gemspec +24 -16
- data/lib/god.rb +261 -204
- data/lib/god/behavior.rb +14 -14
- data/lib/god/behaviors/clean_pid_file.rb +5 -5
- data/lib/god/behaviors/clean_unix_socket.rb +10 -10
- data/lib/god/behaviors/notify_when_flapping.rb +12 -12
- data/lib/god/cli/command.rb +59 -46
- data/lib/god/cli/run.rb +33 -37
- data/lib/god/cli/version.rb +6 -6
- data/lib/god/compat19.rb +1 -4
- data/lib/god/condition.rb +21 -21
- data/lib/god/conditions/always.rb +19 -6
- data/lib/god/conditions/complex.rb +18 -18
- data/lib/god/conditions/cpu_usage.rb +14 -14
- data/lib/god/conditions/degrading_lambda.rb +8 -8
- data/lib/god/conditions/disk_usage.rb +5 -5
- data/lib/god/conditions/flapping.rb +23 -23
- data/lib/god/conditions/http_response_code.rb +35 -19
- data/lib/god/conditions/lambda.rb +2 -2
- data/lib/god/conditions/memory_usage.rb +13 -13
- data/lib/god/conditions/process_exits.rb +14 -20
- data/lib/god/conditions/process_running.rb +16 -25
- data/lib/god/conditions/socket_responding.rb +132 -0
- data/lib/god/conditions/tries.rb +10 -10
- data/lib/god/configurable.rb +10 -10
- data/lib/god/contact.rb +20 -20
- data/lib/god/contacts/email.rb +7 -4
- data/lib/god/contacts/jabber.rb +1 -1
- data/lib/god/driver.rb +96 -64
- data/lib/god/errors.rb +9 -9
- data/lib/god/event_handler.rb +19 -19
- data/lib/god/event_handlers/dummy_handler.rb +4 -4
- data/lib/god/event_handlers/kqueue_handler.rb +3 -3
- data/lib/god/event_handlers/netlink_handler.rb +2 -2
- data/lib/god/logger.rb +13 -13
- data/lib/god/metric.rb +50 -22
- data/lib/god/process.rb +53 -52
- data/lib/god/registry.rb +7 -7
- data/lib/god/simple_logger.rb +14 -14
- data/lib/god/socket.rb +11 -11
- data/lib/god/sugar.rb +30 -15
- data/lib/god/sys_logger.rb +2 -2
- data/lib/god/system/portable_poller.rb +8 -8
- data/lib/god/system/process.rb +8 -8
- data/lib/god/system/slash_proc_poller.rb +13 -13
- data/lib/god/task.rb +237 -188
- data/lib/god/timeline.rb +5 -5
- data/lib/god/trigger.rb +11 -11
- data/lib/god/watch.rb +205 -53
- data/test/configs/child_events/child_events.god +5 -5
- data/test/configs/child_events/simple_server.rb +1 -1
- data/test/configs/child_polls/child_polls.god +4 -4
- data/test/configs/child_polls/simple_server.rb +4 -4
- data/test/configs/complex/complex.god +7 -7
- data/test/configs/complex/simple_server.rb +1 -1
- data/test/configs/contact/contact.god +1 -1
- data/test/configs/contact/simple_server.rb +1 -1
- data/test/configs/daemon_events/daemon_events.god +5 -5
- data/test/configs/daemon_events/simple_server.rb +1 -1
- data/test/configs/daemon_events/simple_server_stop.rb +1 -1
- data/test/configs/daemon_polls/daemon_polls.god +3 -3
- data/test/configs/daemon_polls/simple_server.rb +1 -1
- data/test/configs/degrading_lambda/degrading_lambda.god +3 -3
- data/test/configs/keepalive/keepalive.god +9 -0
- data/test/configs/keepalive/keepalive.rb +12 -0
- data/test/configs/lifecycle/lifecycle.god +2 -2
- data/test/configs/matias/matias.god +6 -6
- data/test/configs/real.rb +7 -7
- data/test/configs/running_load/running_load.god +2 -2
- data/test/configs/stop_options/simple_server.rb +1 -1
- data/test/configs/stress/simple_server.rb +1 -1
- data/test/configs/stress/stress.god +2 -2
- data/test/configs/task/task.god +5 -5
- data/test/configs/test.rb +7 -7
- data/test/helper.rb +8 -8
- data/test/test_behavior.rb +3 -3
- data/test/test_campfire.rb +1 -2
- data/test/test_condition.rb +10 -10
- data/test/test_conditions_disk_usage.rb +12 -12
- data/test/test_conditions_http_response_code.rb +24 -24
- data/test/test_conditions_process_running.rb +7 -7
- data/test/test_conditions_socket_responding.rb +122 -0
- data/test/test_conditions_tries.rb +12 -12
- data/test/test_contact.rb +19 -19
- data/test/test_driver.rb +17 -3
- data/test/test_event_handler.rb +12 -12
- data/test/test_god.rb +195 -117
- data/test/test_handlers_kqueue_handler.rb +4 -4
- data/test/test_jabber.rb +1 -1
- data/test/test_logger.rb +17 -17
- data/test/test_metric.rb +16 -16
- data/test/test_process.rb +47 -41
- data/test/test_prowl.rb +1 -1
- data/test/test_registry.rb +2 -2
- data/test/test_socket.rb +3 -3
- data/test/test_sugar.rb +7 -7
- data/test/test_system_portable_poller.rb +1 -1
- data/test/test_system_process.rb +5 -5
- data/test/test_task.rb +57 -57
- data/test/test_timeline.rb +8 -8
- data/test/test_trigger.rb +16 -16
- data/test/test_watch.rb +69 -62
- metadata +182 -69
- data/lib/god/dependency_graph.rb +0 -41
- data/lib/god/diagnostics.rb +0 -37
- data/test/test_dependency_graph.rb +0 -62
data/test/configs/test.rb
CHANGED
@@ -12,17 +12,17 @@ God.watch do |w|
|
|
12
12
|
w.stop = "mongrel_rails stop -P ./log/mongrel.pid -c #{RAILS_ROOT}"
|
13
13
|
w.group = 'mongrels'
|
14
14
|
w.pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
|
15
|
-
|
15
|
+
|
16
16
|
# clean pid files before start if necessary
|
17
17
|
w.behavior(:clean_pid_file)
|
18
|
-
|
18
|
+
|
19
19
|
# determine the state on startup
|
20
20
|
w.transition(:init, { true => :up, false => :start }) do |on|
|
21
21
|
on.condition(:process_running) do |c|
|
22
22
|
c.running = true
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# determine when process has finished starting
|
27
27
|
w.transition([:start, :restart], :up) do |on|
|
28
28
|
on.condition(:process_running) do |c|
|
@@ -34,7 +34,7 @@ God.watch do |w|
|
|
34
34
|
w.transition(:up, :start) do |on|
|
35
35
|
on.condition(:process_exits)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
# restart if memory or cpu is too high
|
39
39
|
w.transition(:up, :restart) do |on|
|
40
40
|
on.condition(:memory_usage) do |c|
|
@@ -42,13 +42,13 @@ God.watch do |w|
|
|
42
42
|
c.above = 50.megabytes
|
43
43
|
c.times = [3, 5]
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
on.condition(:cpu_usage) do |c|
|
47
47
|
c.interval = 1
|
48
48
|
c.above = 10.percent
|
49
49
|
c.times = [3, 5]
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
on.condition(:http_response_code) do |c|
|
53
53
|
c.host = 'localhost'
|
54
54
|
c.port = port
|
@@ -58,4 +58,4 @@ God.watch do |w|
|
|
58
58
|
c.times = [3, 5]
|
59
59
|
end
|
60
60
|
end
|
61
|
-
end
|
61
|
+
end
|
data/test/helper.rb
CHANGED
@@ -8,7 +8,7 @@ require 'set'
|
|
8
8
|
|
9
9
|
include God
|
10
10
|
|
11
|
-
if Process.uid != 0
|
11
|
+
if Process.uid != 0 and RbConfig::CONFIG['host_os'] == "linux"
|
12
12
|
abort <<-EOF
|
13
13
|
\n
|
14
14
|
*********************************************************************
|
@@ -39,13 +39,13 @@ module God
|
|
39
39
|
true
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
class FakePollCondition < PollCondition
|
44
44
|
def test
|
45
45
|
true
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
class FakeEventCondition < EventCondition
|
50
50
|
def register
|
51
51
|
end
|
@@ -53,7 +53,7 @@ module God
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
module Behaviors
|
58
58
|
class FakeBehavior < Behavior
|
59
59
|
def before_start
|
@@ -64,15 +64,15 @@ module God
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
module Contacts
|
69
69
|
class FakeContact < Contact
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
class InvalidContact
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
def self.reset
|
77
77
|
self.watches = nil
|
78
78
|
self.groups = nil
|
@@ -129,7 +129,7 @@ class Object
|
|
129
129
|
def initialize(ref)
|
130
130
|
@ref = ref
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
def method_missing(sym, *args)
|
134
134
|
@ref.__send__(sym, *args)
|
135
135
|
end
|
data/test/test_behavior.rb
CHANGED
@@ -4,15 +4,15 @@ class TestBehavior < Test::Unit::TestCase
|
|
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_raise NoSuchBehaviorError do
|
10
10
|
Behavior.generate(:foo, nil)
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def test_complain
|
15
15
|
SysLogger.expects(:log).with(:error, 'foo')
|
16
16
|
assert !Behavior.allocate.bypass.complain('foo')
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
data/test/test_campfire.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
|
-
require 'tinder'
|
3
2
|
|
4
3
|
class TestCampfire < Test::Unit::TestCase
|
5
4
|
def setup
|
@@ -20,4 +19,4 @@ class TestCampfire < Test::Unit::TestCase
|
|
20
19
|
Marshmallow::Connection.any_instance.expects(:speak).with('danger', body)
|
21
20
|
@campfire.notify('msg', time, 'prio', 'cat', 'host')
|
22
21
|
end
|
23
|
-
end
|
22
|
+
end
|
data/test/test_condition.rb
CHANGED
@@ -4,19 +4,19 @@ class BadlyImplementedCondition < PollCondition
|
|
4
4
|
end
|
5
5
|
|
6
6
|
class TestCondition < Test::Unit::TestCase
|
7
|
-
|
7
|
+
|
8
8
|
# generate
|
9
|
-
|
9
|
+
|
10
10
|
def test_generate_should_return_an_object_corresponding_to_the_given_type
|
11
11
|
assert_equal Conditions::ProcessRunning, Condition.generate(:process_running, nil).class
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def test_generate_should_raise_on_invalid_type
|
15
15
|
assert_raise NoSuchConditionError do
|
16
16
|
Condition.generate(:foo, nil)
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def test_generate_should_abort_on_event_condition_without_loaded_event_system
|
21
21
|
God::EventHandler.stubs(:operational?).returns(false)
|
22
22
|
assert_abort do
|
@@ -24,25 +24,25 @@ class TestCondition < Test::Unit::TestCase
|
|
24
24
|
Condition.generate(:process_exits, nil).class
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def test_generate_should_return_a_good_error_message_for_invalid_types
|
29
29
|
emsg = "No Condition found with the class name God::Conditions::FooBar"
|
30
30
|
rmsg = nil
|
31
|
-
|
31
|
+
|
32
32
|
begin
|
33
33
|
Condition.generate(:foo_bar, nil)
|
34
34
|
rescue => e
|
35
35
|
rmsg = e.message
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
assert_equal emsg, rmsg
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
# test
|
42
|
-
|
42
|
+
|
43
43
|
def test_test_should_raise_if_not_defined_in_subclass
|
44
44
|
c = BadlyImplementedCondition.new
|
45
|
-
|
45
|
+
|
46
46
|
assert_raise AbstractMethodNotOverriddenError do
|
47
47
|
c.test
|
48
48
|
end
|
@@ -2,49 +2,49 @@ require File.dirname(__FILE__) + '/helper'
|
|
2
2
|
|
3
3
|
class TestConditionsDiskUsage < Test::Unit::TestCase
|
4
4
|
# valid?
|
5
|
-
|
5
|
+
|
6
6
|
def test_valid_should_return_false_if_no_above_given
|
7
7
|
c = Conditions::DiskUsage.new
|
8
8
|
c.mount_point = '/'
|
9
9
|
c.watch = stub(:name => 'foo')
|
10
10
|
assert_equal false, c.valid?
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def test_valid_should_return_false_if_no_mount_point_given
|
14
14
|
c = Conditions::DiskUsage.new
|
15
15
|
c.above = 90
|
16
16
|
c.watch = stub(:name => 'foo')
|
17
17
|
assert_equal false, c.valid?
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def test_valid_should_return_true_if_required_options_all_set
|
21
21
|
c = Conditions::DiskUsage.new
|
22
22
|
c.above = 90
|
23
23
|
c.mount_point = '/'
|
24
24
|
c.watch = stub(:name => 'foo')
|
25
|
-
|
25
|
+
|
26
26
|
assert_equal true, c.valid?
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
# test
|
30
|
-
|
30
|
+
|
31
31
|
def test_test_should_return_true_if_above_limit
|
32
32
|
c = Conditions::DiskUsage.new
|
33
33
|
c.above = 90
|
34
34
|
c.mount_point = '/'
|
35
|
-
|
35
|
+
|
36
36
|
c.expects(:`).returns('91')
|
37
|
-
|
37
|
+
|
38
38
|
assert_equal true, c.test
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def test_test_should_return_false_if_below_limit
|
42
42
|
c = Conditions::DiskUsage.new
|
43
43
|
c.above = 90
|
44
44
|
c.mount_point = '/'
|
45
|
-
|
45
|
+
|
46
46
|
c.expects(:`).returns('90')
|
47
|
-
|
47
|
+
|
48
48
|
assert_equal false, c.test
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|
@@ -14,96 +14,96 @@ class TestHttpResponseCode < Test::Unit::TestCase
|
|
14
14
|
c.prepare
|
15
15
|
c
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# valid?
|
19
|
-
|
19
|
+
|
20
20
|
def test_valid_condition_is_valid
|
21
21
|
c = valid_condition
|
22
22
|
assert c.valid?
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def test_valid_should_return_false_if_both_code_is_and_code_is_not_are_set
|
26
26
|
c = valid_condition do |cc|
|
27
27
|
cc.code_is_not = 500
|
28
28
|
end
|
29
29
|
assert !c.valid?
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def test_valid_should_return_false_if_no_host_set
|
33
33
|
c = valid_condition do |cc|
|
34
34
|
cc.host = nil
|
35
35
|
end
|
36
36
|
assert !c.valid?
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
# test
|
40
|
-
|
40
|
+
|
41
41
|
def test_test_should_return_false_if_code_is_is_set_to_200_but_response_is_500
|
42
42
|
c = valid_condition
|
43
|
-
Net::HTTP.expects(:start).yields(
|
43
|
+
Net::HTTP.any_instance.expects(:start).yields(mock(:read_timeout= => nil, :get => mock(:code => 500)))
|
44
44
|
assert_equal false, c.test
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def test_test_should_return_false_if_code_is_not_is_set_to_200_and_response_is_200
|
48
48
|
c = valid_condition do |cc|
|
49
49
|
cc.code_is = nil
|
50
50
|
cc.code_is_not = [200]
|
51
51
|
end
|
52
|
-
Net::HTTP.expects(:start).yields(
|
52
|
+
Net::HTTP.any_instance.expects(:start).yields(mock(:read_timeout= => nil, :get => mock(:code => 200)))
|
53
53
|
assert_equal false, c.test
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def test_test_should_return_true_if_code_is_is_set_to_200_and_response_is_200
|
57
57
|
c = valid_condition
|
58
|
-
Net::HTTP.expects(:start).yields(
|
58
|
+
Net::HTTP.any_instance.expects(:start).yields(mock(:read_timeout= => nil, :get => mock(:code => 200)))
|
59
59
|
assert_equal true, c.test
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def test_test_should_return_false_if_code_is_not_is_set_to_200_but_response_is_500
|
63
63
|
c = valid_condition do |cc|
|
64
64
|
cc.code_is = nil
|
65
65
|
cc.code_is_not = [200]
|
66
66
|
end
|
67
|
-
Net::HTTP.expects(:start).yields(
|
67
|
+
Net::HTTP.any_instance.expects(:start).yields(mock(:read_timeout= => nil, :get => mock(:code => 500)))
|
68
68
|
assert_equal true, c.test
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
def test_test_should_return_false_if_code_is_is_set_to_200_but_response_times_out
|
72
72
|
c = valid_condition
|
73
|
-
Net::HTTP.expects(:start).raises(Timeout::Error, '')
|
73
|
+
Net::HTTP.any_instance.expects(:start).raises(Timeout::Error, '')
|
74
74
|
assert_equal false, c.test
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def test_test_should_return_true_if_code_is_not_is_set_to_200_and_response_times_out
|
78
78
|
c = valid_condition do |cc|
|
79
79
|
cc.code_is = nil
|
80
80
|
cc.code_is_not = [200]
|
81
81
|
end
|
82
|
-
Net::HTTP.expects(:start).raises(Timeout::Error, '')
|
82
|
+
Net::HTTP.any_instance.expects(:start).raises(Timeout::Error, '')
|
83
83
|
assert_equal true, c.test
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
def test_test_should_return_false_if_code_is_is_set_to_200_but_cant_connect
|
87
87
|
c = valid_condition
|
88
|
-
Net::HTTP.expects(:start).raises(Errno::ECONNREFUSED, '')
|
88
|
+
Net::HTTP.any_instance.expects(:start).raises(Errno::ECONNREFUSED, '')
|
89
89
|
assert_equal false, c.test
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def test_test_should_return_true_if_code_is_not_is_set_to_200_and_cant_connect
|
93
93
|
c = valid_condition do |cc|
|
94
94
|
cc.code_is = nil
|
95
95
|
cc.code_is_not = [200]
|
96
96
|
end
|
97
|
-
Net::HTTP.expects(:start).raises(Errno::ECONNREFUSED, '')
|
97
|
+
Net::HTTP.any_instance.expects(:start).raises(Errno::ECONNREFUSED, '')
|
98
98
|
assert_equal true, c.test
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
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
102
|
c = valid_condition do |cc|
|
103
103
|
cc.times = [2, 2]
|
104
104
|
end
|
105
|
-
Net::HTTP.expects(:start).yields(stub(:read_timeout= => nil, :get => stub(:code => 200))).times(2)
|
105
|
+
Net::HTTP.any_instance.expects(:start).yields(stub(:read_timeout= => nil, :get => stub(:code => 200))).times(2)
|
106
106
|
assert_equal false, c.test
|
107
107
|
assert_equal true, c.test
|
108
108
|
end
|
109
|
-
end
|
109
|
+
end
|
@@ -9,32 +9,32 @@ class TestConditionsProcessRunning < Test::Unit::TestCase
|
|
9
9
|
assert_equal !r, c.test
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def test_not_running_returns_opposite
|
14
14
|
[true, false].each do |r|
|
15
15
|
c = Conditions::ProcessRunning.new
|
16
16
|
c.running = r
|
17
|
-
|
17
|
+
|
18
18
|
File.stubs(:exist?).returns(true)
|
19
19
|
c.stubs(:watch).returns(stub(:pid => 123))
|
20
20
|
File.stubs(:read).returns('5')
|
21
21
|
System::Process.any_instance.stubs(:exists?).returns(false)
|
22
|
-
|
22
|
+
|
23
23
|
assert_equal !r, c.test
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def test_running_returns_same
|
28
28
|
[true, false].each do |r|
|
29
29
|
c = Conditions::ProcessRunning.new
|
30
30
|
c.running = r
|
31
|
-
|
31
|
+
|
32
32
|
File.stubs(:exist?).returns(true)
|
33
33
|
c.stubs(:watch).returns(stub(:pid => 123))
|
34
34
|
File.stubs(:read).returns('5')
|
35
35
|
System::Process.any_instance.stubs(:exists?).returns(true)
|
36
|
-
|
36
|
+
|
37
37
|
assert_equal r, c.test
|
38
38
|
end
|
39
39
|
end
|
40
|
-
end
|
40
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
class TestConditionsSocketResponding < Test::Unit::TestCase
|
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
|
+
# path should not be set for tcp sockets
|
62
|
+
assert_equal c.path, nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_socket_should_set_properties_for_unix
|
66
|
+
c = Conditions::SocketResponding.new
|
67
|
+
c.socket = 'unix:/tmp/process.sock'
|
68
|
+
assert_equal c.family, 'unix'
|
69
|
+
assert_equal c.path, '/tmp/process.sock'
|
70
|
+
# path should not be set for unix domain sockets
|
71
|
+
assert_equal c.port, 0
|
72
|
+
end
|
73
|
+
|
74
|
+
# test
|
75
|
+
|
76
|
+
def test_test_tcp_should_return_false_if_socket_is_listening
|
77
|
+
c = Conditions::SocketResponding.new
|
78
|
+
c.prepare
|
79
|
+
|
80
|
+
TCPSocket.expects(:new).returns(0)
|
81
|
+
assert_equal false, c.test
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_test_tcp_should_return_true_if_no_socket_is_listening
|
85
|
+
c = Conditions::SocketResponding.new
|
86
|
+
c.prepare
|
87
|
+
|
88
|
+
TCPSocket.expects(:new).returns(nil)
|
89
|
+
assert_equal true, c.test
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_test_unix_should_return_false_if_socket_is_listening
|
93
|
+
c = Conditions::SocketResponding.new
|
94
|
+
c.socket = 'unix:/some/path'
|
95
|
+
|
96
|
+
c.prepare
|
97
|
+
UNIXSocket.expects(:new).returns(0)
|
98
|
+
assert_equal false, c.test
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_test_unix_should_return_true_if_no_socket_is_listening
|
102
|
+
|
103
|
+
c = Conditions::SocketResponding.new
|
104
|
+
c.socket = 'unix:/some/path'
|
105
|
+
c.prepare
|
106
|
+
|
107
|
+
UNIXSocket.expects(:new).returns(nil)
|
108
|
+
assert_equal true, c.test
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_test_unix_should_return_true_if_socket_is_listening_2_times
|
112
|
+
|
113
|
+
c = Conditions::SocketResponding.new
|
114
|
+
c.socket = 'unix:/some/path'
|
115
|
+
c.times = [2, 2]
|
116
|
+
c.prepare
|
117
|
+
|
118
|
+
UNIXSocket.expects(:new).returns(nil).times(2)
|
119
|
+
assert_equal false, c.test
|
120
|
+
assert_equal true, c.test
|
121
|
+
end
|
122
|
+
end
|