Skip to content

Commit

Permalink
add support for times and change logic to invert sense of test
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Jenkins committed Oct 5, 2010
1 parent 6505c84 commit 0eb822b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/god/conditions/socket_responding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ def test
s = TCPSocket.new(self.addr, self.port)
rescue SystemCallError
end
status = s.nil? ? false : true
status = s.nil?
elsif self.family == 'unix'
begin
s = UNIXSocket.new(self.path)
rescue SystemCallError
end
status = s.nil? ? false : true
status = s.nil?
else
status = false
end
Expand Down
26 changes: 19 additions & 7 deletions test/test_conditions_socket_responding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,38 +73,50 @@ def test_socket_should_set_properties_for_unix

# test

def test_test_tcp_should_return_true_if_socket_is_listening
def test_test_tcp_should_return_false_if_socket_is_listening
c = Conditions::SocketResponding.new
c.prepare

TCPSocket.expects(:new).returns(0)
assert_equal true, c.test
assert_equal false, c.test
end

def test_test_tcp_should_return_false_if_no_socket_is_listening
def test_test_tcp_should_return_true_if_no_socket_is_listening
c = Conditions::SocketResponding.new
c.prepare

TCPSocket.expects(:new).returns(nil)
assert_equal false, c.test
assert_equal true, c.test
end

def test_test_unix_should_return_true_if_socket_is_listening
def test_test_unix_should_return_false_if_socket_is_listening
c = Conditions::SocketResponding.new
c.socket = 'unix:/some/path'

c.prepare
UNIXSocket.expects(:new).returns(0)
assert_equal true, c.test
assert_equal false, c.test
end

def test_test_unix_should_return_false_if_no_socket_is_listening
def test_test_unix_should_return_true_if_no_socket_is_listening

c = Conditions::SocketResponding.new
c.socket = 'unix:/some/path'
c.prepare

UNIXSocket.expects(:new).returns(nil)
assert_equal true, c.test
end

def test_test_unix_should_return_true_if_socket_is_listening_2_times

c = Conditions::SocketResponding.new
c.socket = 'unix:/some/path'
c.times = [2, 2]
c.prepare

UNIXSocket.expects(:new).returns(nil).times(2)
assert_equal false, c.test
assert_equal true, c.test
end
end

0 comments on commit 0eb822b

Please sign in to comment.