From 2748606273568746dd45803cfb240b99980838bf Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Fri, 10 Dec 2010 11:12:30 -0500 Subject: [PATCH] More portable replica set tests --- test/replica_sets/count_test.rb | 2 +- test/replica_sets/insert_test.rb | 2 +- test/replica_sets/node_type_test.rb | 2 +- test/replica_sets/pooled_insert_test.rb | 2 +- test/replica_sets/query_secondaries.rb | 9 ++++++- test/replica_sets/query_test.rb | 2 +- test/replica_sets/replication_ack_test.rb | 31 ++++++++++------------- 7 files changed, 26 insertions(+), 24 deletions(-) diff --git a/test/replica_sets/count_test.rb b/test/replica_sets/count_test.rb index 09a6712..8587876 100644 --- a/test/replica_sets/count_test.rb +++ b/test/replica_sets/count_test.rb @@ -9,7 +9,7 @@ class ReplicaSetCountTest < Test::Unit::TestCase include Mongo 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.drop_collection("test-sets") @coll = @db.collection("test-sets") diff --git a/test/replica_sets/insert_test.rb b/test/replica_sets/insert_test.rb index 710c83f..baa4fd6 100644 --- a/test/replica_sets/insert_test.rb +++ b/test/replica_sets/insert_test.rb @@ -9,7 +9,7 @@ class ReplicaSetInsertTest < Test::Unit::TestCase include Mongo 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.drop_collection("test-sets") @coll = @db.collection("test-sets") diff --git a/test/replica_sets/node_type_test.rb b/test/replica_sets/node_type_test.rb index 971bfcb..6c72988 100644 --- a/test/replica_sets/node_type_test.rb +++ b/test/replica_sets/node_type_test.rb @@ -9,7 +9,7 @@ class ReplicaSetNodeTypeTest < Test::Unit::TestCase include Mongo 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.drop_collection("test-sets") @coll = @db.collection("test-sets") diff --git a/test/replica_sets/pooled_insert_test.rb b/test/replica_sets/pooled_insert_test.rb index fcb1988..8ad0dee 100644 --- a/test/replica_sets/pooled_insert_test.rb +++ b/test/replica_sets/pooled_insert_test.rb @@ -9,7 +9,7 @@ class ReplicaSetPooledInsertTest < Test::Unit::TestCase include Mongo 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) @db = @conn.db(MONGO_TEST_DB) @db.drop_collection("test-sets") diff --git a/test/replica_sets/query_secondaries.rb b/test/replica_sets/query_secondaries.rb index ecb2430..9ccba77 100644 --- a/test/replica_sets/query_secondaries.rb +++ b/test/replica_sets/query_secondaries.rb @@ -9,12 +9,19 @@ class ReplicaSetQuerySecondariesTest < Test::Unit::TestCase include Mongo 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.drop_collection("test-sets") @coll = @db.collection("test-sets", :safe => {:w => 2, :wtimeout => 100}) 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 @coll.save({:a => 20}) @coll.save({:a => 30}) diff --git a/test/replica_sets/query_test.rb b/test/replica_sets/query_test.rb index 3c238e4..d0f4105 100644 --- a/test/replica_sets/query_test.rb +++ b/test/replica_sets/query_test.rb @@ -9,7 +9,7 @@ class ReplicaSetQueryTest < Test::Unit::TestCase include Mongo 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.drop_collection("test-sets") @coll = @db.collection("test-sets") diff --git a/test/replica_sets/replication_ack_test.rb b/test/replica_sets/replication_ack_test.rb index 9108b00..aa15bd1 100644 --- a/test/replica_sets/replication_ack_test.rb +++ b/test/replica_sets/replication_ack_test.rb @@ -8,13 +8,11 @@ class ReplicaSetAckTest < Test::Unit::TestCase include Mongo 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] - @slaves = @conn.nodes - master + master = [@conn.primary_pool.host, @conn.primary_pool.port] - @slave1 = Mongo::Connection.new(@slaves[0][0], @slaves[0][1], :slave_ok => true) - @slave2 = Mongo::Connection.new(@slaves[1][0], @slaves[1][1], :slave_ok => true) + @slave1 = Mongo::Connection.new(@conn.secondary_pools[0].host, @conn.secondary_pools[0].port, :slave_ok => true) @db = @conn.db(MONGO_TEST_DB) @db.drop_collection("test-sets") @@ -22,47 +20,44 @@ class ReplicaSetAckTest < Test::Unit::TestCase end 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}) 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}) 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}) end end 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, @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 @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, @slave2[MONGO_TEST_DB]["test-sets"].count end def test_last_error_responses 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['lastOp'] @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['lastOp'] @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['n'] == 20 assert response['lastOp']