diff --git a/test/replica_sets/count_test.rb b/test/replica_sets/count_test.rb index 75fed55..a7ec025 100644 --- a/test/replica_sets/count_test.rb +++ b/test/replica_sets/count_test.rb @@ -7,7 +7,10 @@ class ReplicaSetCountTest < Test::Unit::TestCase include Mongo 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.drop_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" 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 diff --git a/test/replica_sets/query_secondaries.rb b/test/replica_sets/query_secondaries.rb index 7647fb6..139ed0c 100644 --- a/test/replica_sets/query_secondaries.rb +++ b/test/replica_sets/query_secondaries.rb @@ -7,7 +7,9 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase include Mongo def setup + RS.restart_killed_nodes @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.drop_collection("test-sets") end @@ -37,7 +39,10 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase @coll.save({:a => 30}) @coll.save({:a => 40}) results = [] + queries_before = @secondary['admin'].command({:serverStatus => 1})['opcounters']['query'] @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?(30) assert results.include?(40)