Implementation of the 'ping' command. Probably better suited for the 'active?' method.

This commit is contained in:
Mauro Pompilio 2011-03-03 19:22:32 +00:00 committed by Kyle Banker
parent 1ad3285767
commit e64f91e013
2 changed files with 16 additions and 2 deletions

View File

@ -329,6 +329,14 @@ module Mongo
self["admin"].command(oh)
end
# Checks if a server is alive. This command will return immediately
# even if the server is in a lock.
#
# @return [Hash]
def ping
self["admin"].command({:ping => 1})
end
# Get the build information for the current connection.
#
# @return [Hash]
@ -336,6 +344,7 @@ module Mongo
self["admin"].command({:buildinfo => 1})
end
# Get the build version of the current server.
#
# @return [Mongo::ServerVersion]
@ -491,7 +500,7 @@ module Mongo
def active?
return false unless connected?
server_info
ping
true
rescue ConnectionFailure

View File

@ -28,6 +28,11 @@ class TestConnection < Test::Unit::TestCase
assert Mongo::Support.ok?(server_info)
end
def test_ping
ping = @conn.ping
assert ping['ok']
end
def test_connection_uri
con = Connection.from_uri("mongodb://#{host_port}")
assert_equal mongo_host, con.primary_pool.host