Fix for connections to replica sets with 1 secondary and 1 arbiter
This commit is contained in:
parent
313ff2e738
commit
b63250e6e4
|
@ -629,9 +629,9 @@ module Mongo
|
|||
|
||||
private
|
||||
|
||||
# Pick a node randomly from the set of possibly secondaries.
|
||||
# Pick a node randomly from the set of possible secondaries.
|
||||
def pick_secondary_for_read
|
||||
if (size = @secondary_pools.size) > 1
|
||||
if (size = @secondary_pools.size) > 0
|
||||
@read_pool = @secondary_pools[rand(size)]
|
||||
end
|
||||
end
|
||||
|
@ -715,9 +715,7 @@ module Mongo
|
|||
if config['secondary']
|
||||
host, port = *node
|
||||
@secondaries << node unless @secondaries.include?(node)
|
||||
if @read_secondary
|
||||
@secondary_pools << Pool.new(self, host, port, :size => @pool_size, :timeout => @timeout)
|
||||
end
|
||||
@secondary_pools << Pool.new(self, host, port, :size => @pool_size, :timeout => @timeout)
|
||||
elsif config['arbiterOnly']
|
||||
@arbiters << node unless @arbiters.include?(node)
|
||||
end
|
||||
|
|
|
@ -3,44 +3,45 @@ require 'mongo'
|
|||
require 'test/unit'
|
||||
require './test/test_helper'
|
||||
|
||||
# NOTE: This test expects a replica set of three nodes to be running on local host.
|
||||
# NOTE: This test expects a replica set of three nodes to be running on TEST_HOST,
|
||||
# on ports TEST_PORT, TEST_PORT + 1, and TEST + 2.
|
||||
class ConnectTest < Test::Unit::TestCase
|
||||
include Mongo
|
||||
|
||||
def test_connect_bad_name
|
||||
assert_raise_error(ReplicaSetConnectionError, "expected 'wrong-repl-set-name'") do
|
||||
Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]],
|
||||
Mongo::Connection.multi([[TEST_HOST, TEST_PORT], [TEST_HOST, TEST_PORT + 1], [TEST_HOST, TEST_PORT + 2]],
|
||||
:rs_name => "wrong-repl-set-name")
|
||||
end
|
||||
end
|
||||
|
||||
def test_connect
|
||||
@conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]],
|
||||
@conn = Mongo::Connection.multi([[TEST_HOST, TEST_PORT], [TEST_HOST, TEST_PORT + 1], [TEST_HOST, TEST_PORT + 2]],
|
||||
:name => "foo")
|
||||
assert @conn.connected?
|
||||
end
|
||||
|
||||
def test_connect_with_first_node_down
|
||||
puts "Please kill the node at 27017."
|
||||
puts "Please kill the node at #{TEST_PORT}."
|
||||
gets
|
||||
|
||||
@conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]])
|
||||
@conn = Mongo::Connection.multi([[TEST_HOST, TEST_PORT], [TEST_HOST, TEST_PORT + 1], [TEST_HOST, TEST_PORT + 2]])
|
||||
assert @conn.connected?
|
||||
end
|
||||
|
||||
def test_connect_with_second_node_down
|
||||
puts "Please kill the node at 27018."
|
||||
puts "Please kill the node at #{TEST_PORT + 1}."
|
||||
gets
|
||||
|
||||
@conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]])
|
||||
@conn = Mongo::Connection.multi([[TEST_HOST, TEST_PORT], [TEST_HOST, TEST_PORT + 1], [TEST_HOST, TEST_PORT + 2]])
|
||||
assert @conn.connected?
|
||||
end
|
||||
|
||||
def test_connect_with_third_node_down
|
||||
puts "Please kill the node at 27019."
|
||||
puts "Please kill the node at #{TEST_PORT + 2}."
|
||||
gets
|
||||
|
||||
@conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]])
|
||||
@conn = Mongo::Connection.multi([[TEST_HOST, TEST_PORT], [TEST_HOST, TEST_PORT + 1], [TEST_HOST, TEST_PORT + 2]])
|
||||
assert @conn.connected?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,13 +25,20 @@ unless defined? MONGO_TEST_DB
|
|||
MONGO_TEST_DB = 'ruby-test-' + BSON::ObjectId.new.to_s
|
||||
end
|
||||
|
||||
unless defined? TEST_PORT
|
||||
TEST_PORT = ENV['MONGO_RUBY_DRIVER_PORT'].to_i || Connection::DEFAULT_PORT
|
||||
end
|
||||
|
||||
unless defined? TEST_HOST
|
||||
TEST_HOST = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
||||
end
|
||||
|
||||
class Test::Unit::TestCase
|
||||
include Mongo
|
||||
include BSON
|
||||
|
||||
def self.standard_connection(options={})
|
||||
Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT, options)
|
||||
Connection.new(TEST_HOST, TEST_PORT, options)
|
||||
end
|
||||
|
||||
def standard_connection(options={})
|
||||
|
@ -43,11 +50,11 @@ class Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def self.mongo_host
|
||||
ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
||||
TEST_HOST
|
||||
end
|
||||
|
||||
def self.mongo_port
|
||||
ENV['MONGO_RUBY_DRIVER_PORT'] ? ENV['MONGO_RUBY_DRIVER_PORT'].to_i : 27017
|
||||
TEST_PORT
|
||||
end
|
||||
|
||||
def host_port
|
||||
|
|
Loading…
Reference in New Issue