From 5930c500b47a5e53ac12335300c7f976f4878db8 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Tue, 30 Nov 2010 12:36:45 -0500 Subject: [PATCH] RUBY-208 test for connection failure. Minor test fix. --- lib/mongo/connection.rb | 4 ++-- test/connection_test.rb | 6 ++++++ test/replica_sets/connect_test.rb | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/mongo/connection.rb b/lib/mongo/connection.rb index 4b414c6..68e7851 100644 --- a/lib/mongo/connection.rb +++ b/lib/mongo/connection.rb @@ -493,13 +493,13 @@ module Mongo 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? end def connecting? - !(connected? && @nodes_to_try.empty?) + @nodes_to_try.length > 0 end # It's possible that we defined connected as all nodes being connected??? diff --git a/test/connection_test.rb b/test/connection_test.rb index d546955..76ca095 100644 --- a/test/connection_test.rb +++ b/test/connection_test.rb @@ -16,6 +16,12 @@ class TestConnection < Test::Unit::TestCase @conn[MONGO_TEST_DB].get_last_error end + def test_connection_failure + assert_raise Mongo::ConnectionFailure do + Mongo::Connection.new('localhost', 27347) + end + end + def test_server_info server_info = @conn.server_info assert server_info.keys.include?("version") diff --git a/test/replica_sets/connect_test.rb b/test/replica_sets/connect_test.rb index 07962a0..e6f9703 100644 --- a/test/replica_sets/connect_test.rb +++ b/test/replica_sets/connect_test.rb @@ -10,7 +10,7 @@ class ConnectTest < Test::Unit::TestCase def test_connect_bad_name assert_raise_error(ReplicaSetConnectionError, "expected 'wrong-repl-set-name'") do Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]], - :name => "wrong-repl-set-name") + :rs_name => "wrong-repl-set-name") end end