RUBY-352 test commands go to primary

This commit is contained in:
Kyle Banker 2011-10-26 12:34:16 -04:00
parent 14593954fa
commit abe3532d2a
2 changed files with 16 additions and 1 deletions

View File

@ -7,7 +7,10 @@ class ReplicaSetCountTest < Test::Unit::TestCase
include Mongo include Mongo
def setup def setup
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]], [RS.host, RS.ports[2]]) @conn = ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]], [RS.host, RS.ports[2]],
:read => :secondary)
assert @conn.primary_pool
@primary = Connection.new(@conn.primary_pool.host, @conn.primary_pool.port)
@db = @conn.db(MONGO_TEST_DB) @db = @conn.db(MONGO_TEST_DB)
@db.drop_collection("test-sets") @db.drop_collection("test-sets")
@coll = @db.collection("test-sets") @coll = @db.collection("test-sets")
@ -33,4 +36,11 @@ class ReplicaSetCountTest < Test::Unit::TestCase
assert_equal 3, @coll.count, "Second count failed" assert_equal 3, @coll.count, "Second count failed"
end end
def test_count_command_sent_to_primary
@coll.insert({:a => 20}, :safe => {:w => 2, :wtimeout => 10000})
count_before = @primary['admin'].command({:serverStatus => 1})['opcounters']['command']
assert_equal 1, @coll.count
count_after = @primary['admin'].command({:serverStatus => 1})['opcounters']['command']
assert_equal 2, count_after - count_before
end
end end

View File

@ -7,7 +7,9 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase
include Mongo include Mongo
def setup def setup
RS.restart_killed_nodes
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], :read => :secondary) @conn = ReplSetConnection.new([RS.host, RS.ports[0]], :read => :secondary)
@secondary = Connection.new(@conn.read_pool.host, @conn.read_pool.port, :slave_ok => true)
@db = @conn.db(MONGO_TEST_DB) @db = @conn.db(MONGO_TEST_DB)
@db.drop_collection("test-sets") @db.drop_collection("test-sets")
end end
@ -37,7 +39,10 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase
@coll.save({:a => 30}) @coll.save({:a => 30})
@coll.save({:a => 40}) @coll.save({:a => 40})
results = [] results = []
queries_before = @secondary['admin'].command({:serverStatus => 1})['opcounters']['query']
@coll.find.each {|r| results << r["a"]} @coll.find.each {|r| results << r["a"]}
queries_after = @secondary['admin'].command({:serverStatus => 1})['opcounters']['query']
assert_equal 1, queries_after - queries_before
assert results.include?(20) assert results.include?(20)
assert results.include?(30) assert results.include?(30)
assert results.include?(40) assert results.include?(40)