Skip to content

Commit

Permalink
Box#alive? to check status of a remote box
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Wiggins committed Mar 7, 2008
1 parent a45f79c commit 711d849
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/rush/box.rb
Expand Up @@ -55,6 +55,11 @@ def bash(command)
connection.bash(command)
end

# Returns true if the box is responding to commands.
def alive?
connection.alive?
end

# This is called automatically the first time an action is invoked, but you
# may wish to call it manually ahead of time in order to have the tunnel
# already set up and running.
Expand Down
5 changes: 5 additions & 0 deletions lib/rush/local.rb
Expand Up @@ -274,4 +274,9 @@ def receive(params)
# No-op for duck typing with remote connection.
def ensure_tunnel
end

# Local connections are always alive.
def alive?
true
end
end
9 changes: 9 additions & 0 deletions lib/rush/remote.rb
Expand Up @@ -127,6 +127,15 @@ def ensure_tunnel
tunnel.ensure_tunnel
end

# Remote connections are alive when the box on the other end is responding
# to commands.
def alive?
index('/', 'alive_check')
true
rescue
false
end

def config
@config ||= Rush::Config.new
end
Expand Down
5 changes: 5 additions & 0 deletions spec/box_spec.rb
Expand Up @@ -26,6 +26,11 @@
@box.bash('cmd').should == 'output'
end

it "checks the connection to determine if it is alive" do
@box.connection.should_receive(:alive?).and_return(true)
@box.should be_alive
end

it "establish_connection to set up the connection manually" do
@box.connection.should_receive(:ensure_tunnel)
@box.establish_connection
Expand Down
4 changes: 4 additions & 0 deletions spec/local_spec.rb
Expand Up @@ -216,4 +216,8 @@
it "ensure_tunnel to match with remote connection" do
@con.ensure_tunnel
end

it "always returns true on alive?" do
@con.should be_alive
end
end
10 changes: 10 additions & 0 deletions spec/remote_spec.rb
Expand Up @@ -112,4 +112,14 @@
@con.tunnel.should_receive(:ensure_tunnel)
@con.ensure_tunnel
end

it "is alive if the box is responding to commands" do
@con.should_receive(:index).and_return(:dummy)
@con.should be_alive
end

it "not alive if an attempted command throws an exception" do
@con.should_receive(:index).and_raise(RuntimeError)
@con.should_not be_alive
end
end

0 comments on commit 711d849

Please sign in to comment.