minor: fix failing tests

This commit is contained in:
Kyle Banker 2011-11-04 15:12:58 -04:00
parent dc4be1afc7
commit 83ac53202e
6 changed files with 30 additions and 7 deletions

View File

@ -483,13 +483,21 @@ module Mongo
def get_local_reader def get_local_reader
self.connections ||= {} 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 self.connections[self.object_id][:reader] ||= checkout_reader
end end
def get_local_writer def get_local_writer
self.connections ||= {} 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 self.connections[self.object_id][:writer] ||= checkout_writer
end end

View File

@ -311,18 +311,24 @@ module Mongo
def get_local_reader def get_local_reader
self.connections ||= {} 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 socket = self.connections[self.object_id][:reader] ||= checkout_reader
@threads_to_sockets[Thread.current][:reader] = socket @threads_to_sockets[Thread.current][:reader] = socket
socket
end end
def get_local_writer def get_local_writer
self.connections ||= {} 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 socket = self.connections[self.object_id][:writer] ||= checkout_writer
@threads_to_sockets[Thread.current][:writer] = socket @threads_to_sockets[Thread.current][:writer] = socket
socket
end end
# Used to close, check in, or refresh sockets held # Used to close, check in, or refresh sockets held

View File

@ -301,6 +301,7 @@ class TestCollection < Test::Unit::TestCase
@conn = standard_connection @conn = standard_connection
@db = @conn[MONGO_TEST_DB] @db = @conn[MONGO_TEST_DB]
@test = @db['test-safe-remove'] @test = @db['test-safe-remove']
@test.remove
@test.save({:a => 50}) @test.save({:a => 50})
assert_equal 1, @test.remove({}, :safe => true)["n"] assert_equal 1, @test.remove({}, :safe => true)["n"]
@test.drop @test.drop
@ -782,6 +783,7 @@ class TestCollection < Test::Unit::TestCase
context "A collection with two records" do context "A collection with two records" do
setup do setup do
@collection = @@db.collection('test-collection') @collection = @@db.collection('test-collection')
@collection.remove
@collection.insert({:name => "Jones"}) @collection.insert({:name => "Jones"})
@collection.insert({:name => "Smith"}) @collection.insert({:name => "Smith"})
end end

View File

@ -53,7 +53,7 @@ class CursorTest < Test::Unit::TestCase
def test_exhaust def test_exhaust
if @@version >= "2.0" if @@version >= "2.0"
@@coll.remove @@coll.remove
data = "1" * 100_000 data = "1" * 10_000
5000.times do |n| 5000.times do |n|
@@coll.insert({:n => n, :data => data}) @@coll.insert({:n => n, :data => data})
end end

View File

@ -12,6 +12,7 @@ class PoolManagerTest < Test::Unit::TestCase
@connection = stub("Connection") @connection = stub("Connection")
@connection.stubs(:connect_timeout).returns(5000) @connection.stubs(:connect_timeout).returns(5000)
@connection.stubs(:pool_size).returns(2) @connection.stubs(:pool_size).returns(2)
@connection.stubs(:pool_timeout).returns(100)
@connection.stubs(:socket_class).returns(TCPSocket) @connection.stubs(:socket_class).returns(TCPSocket)
@connection.stubs(:[]).returns(@db) @connection.stubs(:[]).returns(@db)

View File

@ -74,6 +74,10 @@ class ReadTest < Test::Unit::TestCase
@cursor = @col.find({:a => 1}) @cursor = @col.find({:a => 1})
sock = mock() sock = mock()
sock.expects(:close) 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(:checkout_reader).returns(sock)
@con.expects(:receive_message).with do |o, m, l, s, c, r| @con.expects(:receive_message).with do |o, m, l, s, c, r|
r == nil r == nil
@ -86,6 +90,8 @@ class ReadTest < Test::Unit::TestCase
@cursor = @col.find({:a => 1}, :read => :primary) @cursor = @col.find({:a => 1}, :read => :primary)
sock = mock() sock = mock()
sock.expects(:close) sock.expects(:close)
primary_pool = stub(:sockets_low? => false)
@con.stubs(:primary_pool).returns(primary_pool)
@con.expects(:checkout_writer).returns(sock) @con.expects(:checkout_writer).returns(sock)
@con.expects(:receive_message).with do |o, m, l, s, c, r| @con.expects(:receive_message).with do |o, m, l, s, c, r|
r == nil r == nil