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)
|
self["admin"].command(oh)
|
||||||
end
|
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]
|
# @return [Hash]
|
||||||
def server_info
|
def server_info
|
||||||
self["admin"].command({:buildinfo => 1})
|
self["admin"].command({:buildinfo => 1})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Get the build version of the current server.
|
# Get the build version of the current server.
|
||||||
#
|
#
|
||||||
# @return [Mongo::ServerVersion]
|
# @return [Mongo::ServerVersion]
|
||||||
|
@ -491,7 +500,7 @@ module Mongo
|
||||||
def active?
|
def active?
|
||||||
return false unless connected?
|
return false unless connected?
|
||||||
|
|
||||||
server_info
|
ping
|
||||||
true
|
true
|
||||||
|
|
||||||
rescue ConnectionFailure
|
rescue ConnectionFailure
|
||||||
|
|
|
@ -28,6 +28,11 @@ class TestConnection < Test::Unit::TestCase
|
||||||
assert Mongo::Support.ok?(server_info)
|
assert Mongo::Support.ok?(server_info)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ping
|
||||||
|
ping = @conn.ping
|
||||||
|
assert ping['ok']
|
||||||
|
end
|
||||||
|
|
||||||
def test_connection_uri
|
def test_connection_uri
|
||||||
con = Connection.from_uri("mongodb://#{host_port}")
|
con = Connection.from_uri("mongodb://#{host_port}")
|
||||||
assert_equal mongo_host, con.primary_pool.host
|
assert_equal mongo_host, con.primary_pool.host
|
||||||
|
|
Loading…
Reference in New Issue