Skip to content

Commit 5930c50

Browse files
committed
RUBY-208 test for connection failure. Minor test fix.
1 parent 13f38c5 commit 5930c50

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lib/mongo/connection.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,13 @@ def connect
493493
end
494494
end
495495

496-
pick_secondary_for_read
496+
pick_secondary_for_read if @read_secondary
497497

498498
raise ConnectionFailure, "failed to connect to any given host:port" unless connected?
499499
end
500500

501501
def connecting?
502-
!(connected? && @nodes_to_try.empty?)
502+
@nodes_to_try.length > 0
503503
end
504504

505505
# It's possible that we defined connected as all nodes being connected???

test/connection_test.rb

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ def teardown
1616
@conn[MONGO_TEST_DB].get_last_error
1717
end
1818

19+
def test_connection_failure
20+
assert_raise Mongo::ConnectionFailure do
21+
Mongo::Connection.new('localhost', 27347)
22+
end
23+
end
24+
1925
def test_server_info
2026
server_info = @conn.server_info
2127
assert server_info.keys.include?("version")

test/replica_sets/connect_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ConnectTest < Test::Unit::TestCase
1010
def test_connect_bad_name
1111
assert_raise_error(ReplicaSetConnectionError, "expected 'wrong-repl-set-name'") do
1212
Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]],
13-
:name => "wrong-repl-set-name")
13+
:rs_name => "wrong-repl-set-name")
1414
end
1515
end
1616

0 commit comments

Comments
 (0)