More portable replica set tests

This commit is contained in:
Kyle Banker 2010-12-10 11:12:30 -05:00
parent b63250e6e4
commit 2748606273
7 changed files with 26 additions and 24 deletions

View File

@ -9,7 +9,7 @@ class ReplicaSetCountTest < Test::Unit::TestCase
include Mongo include Mongo
def setup def setup
@conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]]) @conn = Mongo::Connection.multi([[TEST_HOST, TEST_PORT], [TEST_HOST, TEST_PORT + 1], [TEST_HOST, TEST_PORT + 2]])
@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")

View File

@ -9,7 +9,7 @@ class ReplicaSetInsertTest < Test::Unit::TestCase
include Mongo include Mongo
def setup def setup
@conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]]) @conn = Mongo::Connection.multi([[TEST_HOST, TEST_PORT], [TEST_HOST, TEST_PORT + 1], [TEST_HOST, TEST_PORT + 2]])
@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")

View File

@ -9,7 +9,7 @@ class ReplicaSetNodeTypeTest < Test::Unit::TestCase
include Mongo include Mongo
def setup def setup
@conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]]) @conn = Mongo::Connection.multi([[TEST_HOST, TEST_PORT], [TEST_HOST, TEST_PORT + 1], [TEST_HOST, TEST_PORT + 2]])
@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")

View File

@ -9,7 +9,7 @@ class ReplicaSetPooledInsertTest < Test::Unit::TestCase
include Mongo include Mongo
def setup def setup
@conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]], @conn = Mongo::Connection.multi([[TEST_HOST, TEST_PORT], [TEST_HOST, TEST_PORT + 1], [TEST_HOST, TEST_PORT + 2]],
:pool_size => 10, :timeout => 5) :pool_size => 10, :timeout => 5)
@db = @conn.db(MONGO_TEST_DB) @db = @conn.db(MONGO_TEST_DB)
@db.drop_collection("test-sets") @db.drop_collection("test-sets")

View File

@ -9,12 +9,19 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase
include Mongo include Mongo
def setup def setup
@conn = Mongo::Connection.multi([['localhost', 27018]], :read_secondaries => true) @conn = Mongo::Connection.multi([[TEST_HOST, TEST_PORT]], :read_secondary => true)
@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", :safe => {:w => 2, :wtimeout => 100}) @coll = @db.collection("test-sets", :safe => {:w => 2, :wtimeout => 100})
end end
def test_con
assert @conn.primary_pool, "No primary pool!"
assert @conn.read_pool, "No read pool!"
assert @conn.primary_pool.port != @conn.read_pool.port,
"Primary port and read port at the same!"
end
def test_query def test_query
@coll.save({:a => 20}) @coll.save({:a => 20})
@coll.save({:a => 30}) @coll.save({:a => 30})

View File

@ -9,7 +9,7 @@ class ReplicaSetQueryTest < Test::Unit::TestCase
include Mongo include Mongo
def setup def setup
@conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]]) @conn = Mongo::Connection.multi([[TEST_HOST, TEST_PORT], [TEST_HOST, TEST_PORT + 1], [TEST_HOST, TEST_PORT + 2]])
@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")

View File

@ -8,13 +8,11 @@ class ReplicaSetAckTest < Test::Unit::TestCase
include Mongo include Mongo
def setup def setup
@conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]]) @conn = Mongo::Connection.multi([[TEST_HOST, TEST_PORT], [TEST_HOST, TEST_PORT + 1], [TEST_HOST, TEST_PORT + 2]])
master = [@conn.host, @conn.port] master = [@conn.primary_pool.host, @conn.primary_pool.port]
@slaves = @conn.nodes - master
@slave1 = Mongo::Connection.new(@slaves[0][0], @slaves[0][1], :slave_ok => true) @slave1 = Mongo::Connection.new(@conn.secondary_pools[0].host, @conn.secondary_pools[0].port, :slave_ok => true)
@slave2 = Mongo::Connection.new(@slaves[1][0], @slaves[1][1], :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")
@ -22,47 +20,44 @@ class ReplicaSetAckTest < Test::Unit::TestCase
end end
def test_safe_mode_with_w_failure def test_safe_mode_with_w_failure
assert_raise_error OperationFailure, "timed out waiting for slaves" do assert_raise_error OperationFailure, "timeout" do
@col.insert({:foo => 1}, :safe => {:w => 4, :wtimeout => 1, :fsync => true}) @col.insert({:foo => 1}, :safe => {:w => 4, :wtimeout => 1, :fsync => true})
end end
assert_raise_error OperationFailure, "timed out waiting for slaves" do assert_raise_error OperationFailure, "timeout" do
@col.update({:foo => 1}, {:foo => 2}, :safe => {:w => 4, :wtimeout => 1, :fsync => true}) @col.update({:foo => 1}, {:foo => 2}, :safe => {:w => 4, :wtimeout => 1, :fsync => true})
end end
assert_raise_error OperationFailure, "timed out waiting for slaves" do assert_raise_error OperationFailure, "timeout" do
@col.remove({:foo => 2}, :safe => {:w => 4, :wtimeout => 1, :fsync => true}) @col.remove({:foo => 2}, :safe => {:w => 4, :wtimeout => 1, :fsync => true})
end end
end end
def test_safe_mode_replication_ack def test_safe_mode_replication_ack
@col.insert({:baz => "bar"}, :safe => {:w => 3, :wtimeout => 1000}) @col.insert({:baz => "bar"}, :safe => {:w => 2, :wtimeout => 1000})
assert @col.insert({:foo => "0" * 10000}, :safe => {:w => 3, :wtimeout => 1000}) assert @col.insert({:foo => "0" * 10000}, :safe => {:w => 2, :wtimeout => 1000})
assert_equal 2, @slave1[MONGO_TEST_DB]["test-sets"].count assert_equal 2, @slave1[MONGO_TEST_DB]["test-sets"].count
assert_equal 2, @slave2[MONGO_TEST_DB]["test-sets"].count
assert @col.update({:baz => "bar"}, {:baz => "foo"}, :safe => {:w => 3, :wtimeout => 1000}) assert @col.update({:baz => "bar"}, {:baz => "foo"}, :safe => {:w => 2, :wtimeout => 1000})
assert @slave1[MONGO_TEST_DB]["test-sets"].find_one({:baz => "foo"}) assert @slave1[MONGO_TEST_DB]["test-sets"].find_one({:baz => "foo"})
assert @slave2[MONGO_TEST_DB]["test-sets"].find_one({:baz => "foo"})
assert @col.remove({}, :safe => {:w => 3, :wtimeout => 1000}) assert @col.remove({}, :safe => {:w => 2, :wtimeout => 1000})
assert_equal 0, @slave1[MONGO_TEST_DB]["test-sets"].count assert_equal 0, @slave1[MONGO_TEST_DB]["test-sets"].count
assert_equal 0, @slave2[MONGO_TEST_DB]["test-sets"].count
end end
def test_last_error_responses def test_last_error_responses
20.times { @col.insert({:baz => "bar"}) } 20.times { @col.insert({:baz => "bar"}) }
response = @db.get_last_error(:w => 3, :wtimeout => 10000) response = @db.get_last_error(:w => 2, :wtimeout => 10000)
assert response['ok'] == 1 assert response['ok'] == 1
assert response['lastOp'] assert response['lastOp']
@col.update({}, {:baz => "foo"}, :multi => true) @col.update({}, {:baz => "foo"}, :multi => true)
response = @db.get_last_error(:w => 3, :wtimeout => 1000) response = @db.get_last_error(:w => 2, :wtimeout => 1000)
assert response['ok'] == 1 assert response['ok'] == 1
assert response['lastOp'] assert response['lastOp']
@col.remove({}) @col.remove({})
response = @db.get_last_error(:w => 3, :wtimeout => 1000) response = @db.get_last_error(:w => 2, :wtimeout => 1000)
assert response['ok'] == 1 assert response['ok'] == 1
assert response['n'] == 20 assert response['n'] == 20
assert response['lastOp'] assert response['lastOp']