Implementation of the 'ping' command. Probably better suited for the 'active?' method.
This commit is contained in:
parent
1ad3285767
commit
e64f91e013
@ -329,13 +329,22 @@ module Mongo
|
||||
self["admin"].command(oh)
|
||||
end
|
||||
|
||||
# Get the build information for the current connection.
|
||||
# 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]
|
||||
def server_info
|
||||
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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user