RUBY-208 test for connection failure. Minor test fix.

This commit is contained in:
Kyle Banker 2010-11-30 12:36:45 -05:00
parent 13f38c58b7
commit 5930c500b4
3 changed files with 9 additions and 3 deletions

View File

@ -493,13 +493,13 @@ module Mongo
end end
end end
pick_secondary_for_read pick_secondary_for_read if @read_secondary
raise ConnectionFailure, "failed to connect to any given host:port" unless connected? raise ConnectionFailure, "failed to connect to any given host:port" unless connected?
end end
def connecting? def connecting?
!(connected? && @nodes_to_try.empty?) @nodes_to_try.length > 0
end end
# It's possible that we defined connected as all nodes being connected??? # It's possible that we defined connected as all nodes being connected???

View File

@ -16,6 +16,12 @@ class TestConnection < Test::Unit::TestCase
@conn[MONGO_TEST_DB].get_last_error @conn[MONGO_TEST_DB].get_last_error
end end
def test_connection_failure
assert_raise Mongo::ConnectionFailure do
Mongo::Connection.new('localhost', 27347)
end
end
def test_server_info def test_server_info
server_info = @conn.server_info server_info = @conn.server_info
assert server_info.keys.include?("version") assert server_info.keys.include?("version")

View File

@ -10,7 +10,7 @@ class ConnectTest < Test::Unit::TestCase
def test_connect_bad_name def test_connect_bad_name
assert_raise_error(ReplicaSetConnectionError, "expected 'wrong-repl-set-name'") do assert_raise_error(ReplicaSetConnectionError, "expected 'wrong-repl-set-name'") do
Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]], Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]],
:name => "wrong-repl-set-name") :rs_name => "wrong-repl-set-name")
end end
end end