From 15dce65e5a6b2ae535f7956306d06682fd7145da Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Fri, 20 Jan 2012 13:31:04 -0500 Subject: [PATCH] RUBY-398 skip seed node if neither primary nor secondary --- lib/mongo/util/node.rb | 6 +++++- test/replica_sets/complex_connect_test.rb | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/mongo/util/node.rb b/lib/mongo/util/node.rb index f33e9f1..5de8ba4 100644 --- a/lib/mongo/util/node.rb +++ b/lib/mongo/util/node.rb @@ -166,12 +166,16 @@ module Mongo [host, port] 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) if !config['hosts'] message = "Will not connect to #{host_string} because it's not a member " + "of a replica set." 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 diff --git a/test/replica_sets/complex_connect_test.rb b/test/replica_sets/complex_connect_test.rb index 39ec383..145ceeb 100644 --- a/test/replica_sets/complex_connect_test.rb +++ b/test/replica_sets/complex_connect_test.rb @@ -1,4 +1,5 @@ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) +require 'logger' require './test/replica_sets/rs_test_helper' class ComplexConnectTest < Test::Unit::TestCase @@ -10,10 +11,11 @@ class ComplexConnectTest < Test::Unit::TestCase end def test_complex_connect + logger = Logger.new(STDOUT) 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]], - [self.rs.host, self.rs.ports[0]]) + [self.rs.host, self.rs.ports[0]], :logger => logger) @conn['test']['foo'].insert({:a => 1}) assert @conn['test']['foo'].find_one