From 83ac53202e6a392ddbbeeecac70bc6a4368f231b Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Fri, 4 Nov 2011 15:12:58 -0400 Subject: [PATCH] minor: fix failing tests --- lib/mongo/connection.rb | 12 ++++++++++-- lib/mongo/repl_set_connection.rb | 14 ++++++++++---- test/collection_test.rb | 2 ++ test/cursor_test.rb | 2 +- test/unit/pool_manager_test.rb | 1 + test/unit/read_test.rb | 6 ++++++ 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/mongo/connection.rb b/lib/mongo/connection.rb index 3908a5e..0115433 100644 --- a/lib/mongo/connection.rb +++ b/lib/mongo/connection.rb @@ -483,13 +483,21 @@ module Mongo def get_local_reader self.connections ||= {} - self.connections[self.object_id] ||= {} + if !connected? && self.connections[self.object_id] + self.connections[self.object_id] + else + self.connections[self.object_id] = {} + end self.connections[self.object_id][:reader] ||= checkout_reader end def get_local_writer self.connections ||= {} - self.connections[self.object_id] ||= {} + if !connected? && self.connections[self.object_id] + self.connections[self.object_id] + else + self.connections[self.object_id] = {} + end self.connections[self.object_id][:writer] ||= checkout_writer end diff --git a/lib/mongo/repl_set_connection.rb b/lib/mongo/repl_set_connection.rb index 9a86a0b..ed3b7df 100644 --- a/lib/mongo/repl_set_connection.rb +++ b/lib/mongo/repl_set_connection.rb @@ -311,18 +311,24 @@ module Mongo def get_local_reader self.connections ||= {} - self.connections[self.object_id] ||= {} + if !connected? && self.connections[self.object_id] + self.connections[self.object_id] + else + self.connections[self.object_id] = {} + end socket = self.connections[self.object_id][:reader] ||= checkout_reader @threads_to_sockets[Thread.current][:reader] = socket - socket end def get_local_writer self.connections ||= {} - self.connections[self.object_id] ||= {} + if !connected? && self.connections[self.object_id] + self.connections[self.object_id] + else + self.connections[self.object_id] = {} + end socket = self.connections[self.object_id][:writer] ||= checkout_writer @threads_to_sockets[Thread.current][:writer] = socket - socket end # Used to close, check in, or refresh sockets held diff --git a/test/collection_test.rb b/test/collection_test.rb index ca8939e..b34635e 100644 --- a/test/collection_test.rb +++ b/test/collection_test.rb @@ -301,6 +301,7 @@ class TestCollection < Test::Unit::TestCase @conn = standard_connection @db = @conn[MONGO_TEST_DB] @test = @db['test-safe-remove'] + @test.remove @test.save({:a => 50}) assert_equal 1, @test.remove({}, :safe => true)["n"] @test.drop @@ -782,6 +783,7 @@ class TestCollection < Test::Unit::TestCase context "A collection with two records" do setup do @collection = @@db.collection('test-collection') + @collection.remove @collection.insert({:name => "Jones"}) @collection.insert({:name => "Smith"}) end diff --git a/test/cursor_test.rb b/test/cursor_test.rb index 9ade4fb..c64c04b 100644 --- a/test/cursor_test.rb +++ b/test/cursor_test.rb @@ -53,7 +53,7 @@ class CursorTest < Test::Unit::TestCase def test_exhaust if @@version >= "2.0" @@coll.remove - data = "1" * 100_000 + data = "1" * 10_000 5000.times do |n| @@coll.insert({:n => n, :data => data}) end diff --git a/test/unit/pool_manager_test.rb b/test/unit/pool_manager_test.rb index def8cb1..b235b7a 100644 --- a/test/unit/pool_manager_test.rb +++ b/test/unit/pool_manager_test.rb @@ -12,6 +12,7 @@ class PoolManagerTest < Test::Unit::TestCase @connection = stub("Connection") @connection.stubs(:connect_timeout).returns(5000) @connection.stubs(:pool_size).returns(2) + @connection.stubs(:pool_timeout).returns(100) @connection.stubs(:socket_class).returns(TCPSocket) @connection.stubs(:[]).returns(@db) diff --git a/test/unit/read_test.rb b/test/unit/read_test.rb index b27f2ef..7f58700 100644 --- a/test/unit/read_test.rb +++ b/test/unit/read_test.rb @@ -74,6 +74,10 @@ class ReadTest < Test::Unit::TestCase @cursor = @col.find({:a => 1}) sock = mock() sock.expects(:close) + read_pool = stub(:sockets_low? => false) + @con.stubs(:read_pool).returns(read_pool) + primary_pool = stub(:sockets_low? => false) + @con.stubs(:primary_pool).returns(primary_pool) @con.expects(:checkout_reader).returns(sock) @con.expects(:receive_message).with do |o, m, l, s, c, r| r == nil @@ -86,6 +90,8 @@ class ReadTest < Test::Unit::TestCase @cursor = @col.find({:a => 1}, :read => :primary) sock = mock() sock.expects(:close) + primary_pool = stub(:sockets_low? => false) + @con.stubs(:primary_pool).returns(primary_pool) @con.expects(:checkout_writer).returns(sock) @con.expects(:receive_message).with do |o, m, l, s, c, r| r == nil