RUBY-398 skip seed node if neither primary nor secondary
This commit is contained in:
parent
68c613ce79
commit
15dce65e5a
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue