From fbdf16bd48129d549b6a55ebe32b8c1c7104d103 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Mon, 7 Nov 2011 13:36:57 -0500 Subject: [PATCH] minor: text fixes --- lib/mongo/repl_set_connection.rb | 9 +++++++++ lib/mongo/util/node.rb | 6 +++--- lib/mongo/util/pool_manager.rb | 4 +++- test/replica_sets/refresh_test.rb | 1 - test/test_helper.rb | 10 ++++++++-- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/mongo/repl_set_connection.rb b/lib/mongo/repl_set_connection.rb index ed3b7df..ced0f93 100644 --- a/lib/mongo/repl_set_connection.rb +++ b/lib/mongo/repl_set_connection.rb @@ -317,6 +317,11 @@ module Mongo self.connections[self.object_id] = {} end socket = self.connections[self.object_id][:reader] ||= checkout_reader + if self.read_pool != @sockets_to_pools[socket] + checkin(socket) + socket = self.connections[self.object_id][:reader] = checkout_reader + end + @threads_to_sockets[Thread.current][:reader] = socket end @@ -328,6 +333,10 @@ module Mongo self.connections[self.object_id] = {} end socket = self.connections[self.object_id][:writer] ||= checkout_writer + if self.primary_pool != @sockets_to_pools[socket] + checkin(socket) + socket = self.connections[self.object_id][:writer] = checkout_writer + end @threads_to_sockets[Thread.current][:writer] = socket end diff --git a/lib/mongo/util/node.rb b/lib/mongo/util/node.rb index d154a8d..db3ac78 100644 --- a/lib/mongo/util/node.rb +++ b/lib/mongo/util/node.rb @@ -60,11 +60,11 @@ module Mongo end def close - if @socket + if @socket && !@socket.closed? @socket.close - @socket = nil - @config = nil end + @socket = nil + @config = nil end def connected? diff --git a/lib/mongo/util/pool_manager.rb b/lib/mongo/util/pool_manager.rb index e63e79a..261b152 100644 --- a/lib/mongo/util/pool_manager.rb +++ b/lib/mongo/util/pool_manager.rb @@ -257,7 +257,9 @@ module Mongo def get_valid_seed_node @seeds.each do |seed| node = Mongo::Node.new(self.connection, seed) - if node.connect && node.set_config + if !node.connect + next + elsif node.set_config return node else node.close diff --git a/test/replica_sets/refresh_test.rb b/test/replica_sets/refresh_test.rb index ff1b8a3..fa0a215 100644 --- a/test/replica_sets/refresh_test.rb +++ b/test/replica_sets/refresh_test.rb @@ -87,7 +87,6 @@ class ReplicaSetRefreshTest < Test::Unit::TestCase @conn = ReplSetConnection.new([self.rs.host, self.rs.ports[0]], [self.rs.host, self.rs.ports[1]], [self.rs.host, self.rs.ports[2]], :refresh_interval => 2, :refresh_mode => :async) - @conn.secondary_pools assert_equal 2, @conn.secondary_pools.length assert_equal 2, @conn.secondaries.length diff --git a/test/test_helper.rb b/test/test_helper.rb index e3cb492..5e63b88 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -93,8 +93,14 @@ class Test::Unit::TestCase begin yield rescue => e - assert_equal klass, e.class - assert e.message.include?(message), "#{e.message} does not include #{message}." + if klass.to_s != e.class.to_s + flunk "Expected exception class #{klass} but got #{e.class}.\n #{e.backtrace}" + end + + if !e.message.include?(message) + p e.backtrace + flunk "#{e.message} does not include #{message}.\n#{e.backtrace}" + end else flunk "Expected assertion #{klass} but none was raised." end