Better tests for reading rs secondaries
This commit is contained in:
parent
70135a6b67
commit
1095a39299
@ -14,6 +14,12 @@ class ConnectTest < Test::Unit::TestCase
|
||||
RS.restart_killed_nodes
|
||||
end
|
||||
|
||||
def test_connect_with_deprecated_multi
|
||||
@conn = Connection.multi([[RS.host, RS.ports[0]], [RS.host, RS.ports[1]]], :name => RS.name)
|
||||
assert @conn.connected?
|
||||
assert @conn.is_a?(ReplSetConnection)
|
||||
end
|
||||
|
||||
def test_connect_bad_name
|
||||
assert_raise_error(ReplicaSetConnectionError, "-wrong") do
|
||||
ReplSetConnection.new([RS.host, RS.ports[0]], [RS.host, RS.ports[1]],
|
||||
|
@ -10,7 +10,6 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase
|
||||
@conn = ReplSetConnection.new([RS.host, RS.ports[0]], :read_secondary => true)
|
||||
@db = @conn.db(MONGO_TEST_DB)
|
||||
@db.drop_collection("test-sets")
|
||||
@coll = @db.collection("test-sets", :safe => {:w => 2, :wtimeout => 100})
|
||||
end
|
||||
|
||||
def teardown
|
||||
@ -24,7 +23,8 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase
|
||||
"Primary port and read port at the same!"
|
||||
end
|
||||
|
||||
def test_query
|
||||
def test_query_secondaries
|
||||
@coll = @db.collection("test-sets", :safe => {:w => 3, :wtimeout => 10000})
|
||||
@coll.save({:a => 20})
|
||||
@coll.save({:a => 30})
|
||||
@coll.save({:a => 40})
|
||||
@ -45,4 +45,36 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_kill_primary
|
||||
@coll = @db.collection("test-sets", :safe => {:w => 3, :wtimeout => 10000})
|
||||
@coll.save({:a => 20})
|
||||
@coll.save({:a => 30})
|
||||
assert_equal 2, @coll.find.to_a.length
|
||||
|
||||
# Should still be able to read immediately after killing master node
|
||||
RS.kill_primary
|
||||
assert_equal 2, @coll.find.to_a.length
|
||||
end
|
||||
|
||||
def test_kill_secondary
|
||||
@coll = @db.collection("test-sets", {:safe => {:w => 3, :wtimeout => 10000}})
|
||||
@coll.save({:a => 20})
|
||||
@coll.save({:a => 30})
|
||||
assert_equal 2, @coll.find.to_a.length
|
||||
|
||||
read_node = RS.get_node_from_port(@conn.read_pool.port)
|
||||
RS.kill(read_node)
|
||||
|
||||
# Should fail immediately on next read
|
||||
assert_raise ConnectionFailure do
|
||||
@coll.find.to_a.length
|
||||
end
|
||||
|
||||
# Should eventually reconnect and be able to read
|
||||
rescue_connection_failure do
|
||||
length = @coll.find.to_a.length
|
||||
assert_equal 2, length
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -229,7 +229,7 @@ class ReplSetManager
|
||||
while count < @retries do
|
||||
begin
|
||||
return yield
|
||||
rescue exception
|
||||
rescue exception, Mongo::ConnectionFailure
|
||||
sleep(1)
|
||||
count += 1
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user