Skip to content

Commit

Permalink
Pool manager unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
banker committed Sep 2, 2011
1 parent 30f595a commit b0b1c04
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongo/util/pool_manager.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class PoolManager


attr_reader :connection, :seeds, :arbiters, :primary, :secondaries, attr_reader :connection, :seeds, :arbiters, :primary, :secondaries,
:primary_pool, :read_pool, :secondary_pools, :hosts, :nodes, :max_bson_size, :primary_pool, :read_pool, :secondary_pools, :hosts, :nodes, :max_bson_size,
:tags_to_pools :tags_to_pools, :members


def initialize(connection, seeds) def initialize(connection, seeds)
@connection = connection @connection = connection
Expand Down
49 changes: 49 additions & 0 deletions test/unit/pool_manager_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,49 @@
require './test/test_helper'
include Mongo

class PoolManagerTest < Test::Unit::TestCase

context "Initialization: " do

def setup
TCPSocket.stubs(:new).returns(new_mock_socket)
@db = new_mock_db

@connection = stub("Connection")
@connection.stubs(:connect_timeout).returns(5000)
@connection.stubs(:pool_size).returns(2)
@connection.stubs(:socket_class).returns(TCPSocket)
@connection.stubs(:[]).returns(@db)
end

should "populate pools correctly" do
@connection.stubs(:replica_set_name).returns(nil)
@connection.stubs(:log)
@arbiters = ['localhost:27020']
@hosts = ['localhost:27017', 'localhost:27018', 'localhost:27019',
'localhost:27020']

@db.stubs(:command).returns(
# First call to get a socket.
{'ismaster' => true, 'hosts' => @hosts, 'arbiters' => @arbiters},

# Subsequent calls to configure pools.
{'ismaster' => true, 'hosts' => @hosts, 'arbiters' => @arbiters},
{'secondary' => true, 'hosts' => @hosts, 'arbiters' => @arbiters},
{'secondary' => true, 'hosts' => @hosts, 'arbiters' => @arbiters},
{'arbiterOnly' => true, 'hosts' => @hosts, 'arbiters' => @arbiters})

seeds = [['localhost', 27017]]
manager = Mongo::PoolManager.new(@connection, seeds)
manager.connect

assert_equal ['localhost', 27017], manager.primary
assert_equal 27017, manager.primary_pool.port
assert_equal 2, manager.secondaries.length
assert_equal 27018, manager.secondary_pools[0].port
assert_equal [['localhost', 27020]], manager.arbiters
end

end

end

0 comments on commit b0b1c04

Please sign in to comment.