RUBY-398 skip seed node if neither primary nor secondary

This commit is contained in:
Kyle Banker 2012-01-20 13:31:04 -05:00
parent 68c613ce79
commit 15dce65e5a
2 changed files with 8 additions and 2 deletions

View File

@ -166,12 +166,16 @@ module Mongo
[host, port] [host, port]
end end
# Ensure that this node is a member of a replica set. # Ensure that this node is a healty member of a replica set.
def check_set_membership(config) def check_set_membership(config)
if !config['hosts'] if !config['hosts']
message = "Will not connect to #{host_string} because it's not a member " + message = "Will not connect to #{host_string} because it's not a member " +
"of a replica set." "of a replica set."
raise ConnectionFailure, message raise ConnectionFailure, message
elsif config['hosts'].length == 1 && !config['ismaster'] &&
!config['secondary']
message = "Attempting to connect to an unhealthy, single-node replica set."
raise ConnectionFailure, message
end end
end end

View File

@ -1,4 +1,5 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'logger'
require './test/replica_sets/rs_test_helper' require './test/replica_sets/rs_test_helper'
class ComplexConnectTest < Test::Unit::TestCase class ComplexConnectTest < Test::Unit::TestCase
@ -10,10 +11,11 @@ class ComplexConnectTest < Test::Unit::TestCase
end end
def test_complex_connect def test_complex_connect
logger = Logger.new(STDOUT)
primary = Connection.new(self.rs.host, self.rs.ports[0]) primary = Connection.new(self.rs.host, self.rs.ports[0])
@conn = ReplSetConnection.new([self.rs.host, self.rs.ports[2]], [self.rs.host, self.rs.ports[1]], @conn = ReplSetConnection.new([self.rs.host, self.rs.ports[2]], [self.rs.host, self.rs.ports[1]],
[self.rs.host, self.rs.ports[0]]) [self.rs.host, self.rs.ports[0]], :logger => logger)
@conn['test']['foo'].insert({:a => 1}) @conn['test']['foo'].insert({:a => 1})
assert @conn['test']['foo'].find_one assert @conn['test']['foo'].find_one