Skip to content

Commit 4ebc6df

Browse files
committed
RUBY-800 Adding in op_timeout to test clients
1 parent a79e2ef commit 4ebc6df

15 files changed

+30
-21
lines changed

test/functional/client_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ def test_connection_activity
452452
end
453453

454454
def test_operation_timeout_with_active
455-
conn = standard_connection
455+
conn = MongoClient.new
456+
authenticate_client(conn)
456457
assert conn.active?
457458
assert_equal Mongo::MongoClient::DEFAULT_OP_TIMEOUT, conn.op_timeout
458459

test/helpers/test_unit.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
TEST_HOST = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' unless defined? TEST_HOST
16-
TEST_DATA = File.join(File.dirname(__FILE__), 'fixtures/data')
17-
TEST_BASE = Test::Unit::TestCase
15+
TEST_HOST = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' unless defined? TEST_HOST
16+
TEST_DATA = File.join(File.dirname(__FILE__), 'fixtures/data')
17+
TEST_OP_TIMEOUT = 40
18+
TEST_BASE = Test::Unit::TestCase
1819

1920
unless defined? TEST_PORT
2021
TEST_PORT = if ENV['MONGO_RUBY_DRIVER_PORT']
@@ -89,16 +90,17 @@ def rescue_connection_failure(max_retries=30)
8990
#
9091
# @return [MongoClient] The client instance.
9192
def self.standard_connection(options={}, legacy=false)
93+
opts = options[:op_timeout] ? options : options.merge(:op_timeout => TEST_OP_TIMEOUT)
9294
if legacy
9395
silently do
9496
# We have to create the Connection object directly here instead of using TEST_URI
9597
# because Connection#from_uri ends up creating a MongoClient object.
96-
conn = Connection.new(TEST_HOST, TEST_PORT, options)
98+
conn = Connection.new(TEST_HOST, TEST_PORT, opts)
9799
conn[TEST_DB].authenticate(TEST_USER, TEST_USER_PWD)
98100
conn
99101
end
100102
else
101-
MongoClient.from_uri(TEST_URI, options)
103+
MongoClient.from_uri(TEST_URI, opts)
102104
end
103105
end
104106

test/replica_set/authentication_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ReplicaSetAuthenticationTest < Test::Unit::TestCase
2828

2929
def setup
3030
ensure_cluster(:rs)
31-
@client = MongoReplicaSetClient.from_uri(@uri)
31+
@client = MongoReplicaSetClient.from_uri(@uri, :op_timeout => TEST_OP_TIMEOUT)
3232
@admin = @client['admin']
3333
@version = @client.server_version
3434
@db = @client['ruby-test']

test/replica_set/basic_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def setup
2121
end
2222

2323
def test_connect
24-
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name)
24+
client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :name => @rs.repl_set_name, :op_timeout => TEST_OP_TIMEOUT)
2525
assert client.connected?
2626
assert_equal @rs.primary_name, client.primary.join(':')
2727
assert_equal @rs.secondary_names.sort, client.secondaries.collect{|s| s.join(':')}.sort

test/replica_set/client_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def teardown
2626
end
2727

2828
def test_reconnection
29-
@client = MongoReplicaSetClient.from_uri(@uri)
29+
@client = MongoReplicaSetClient.from_uri(@uri, :op_timeout => TEST_OP_TIMEOUT)
3030
assert @client.connected?
3131

3232
manager = @client.local_manager

test/replica_set/count_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ReplicaSetCountTest < Test::Unit::TestCase
1818

1919
def setup
2020
ensure_cluster(:rs)
21-
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :read => :primary_preferred)
21+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :read => :primary_preferred, :op_timeout => TEST_OP_TIMEOUT)
2222
authenticate_client(@client)
2323
assert @client.primary_pool
2424
@primary = MongoClient.new(@client.primary_pool.host, @client.primary_pool.port)

test/replica_set/cursor_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_intervening_query_secondary
6565
def setup_client(read=:primary)
6666
route_read ||= read
6767
# Setup ReplicaSet Connection
68-
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :read => read)
68+
@client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :read => read, :op_timeout => TEST_OP_TIMEOUT)
6969
authenticate_client(@client)
7070

7171
@db = @client.db(TEST_DB)

test/replica_set/insert_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ReplicaSetInsertTest < Test::Unit::TestCase
1818

1919
def setup
2020
ensure_cluster(:rs)
21-
@client = MongoReplicaSetClient.from_uri(@uri)
21+
@client = MongoReplicaSetClient.from_uri(@uri, :op_timeout => TEST_OP_TIMEOUT)
2222
@version = @client.server_version
2323
@db = @client.db(TEST_DB)
2424
@db.drop_collection("test-sets")

test/replica_set/max_values_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MaxValuesTest < Test::Unit::TestCase
2020

2121
def setup
2222
ensure_cluster(:rs)
23-
@client = MongoReplicaSetClient.from_uri(@uri)
23+
@client = MongoReplicaSetClient.from_uri(@uri, :op_timeout => TEST_OP_TIMEOUT)
2424
@db = new_mock_db
2525
@client.stubs(:[]).returns(@db)
2626
@ismaster = {

test/replica_set/pinning_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class ReplicaSetPinningTest < Test::Unit::TestCase
1818
def setup
1919
ensure_cluster(:rs)
20-
@client = MongoReplicaSetClient.from_uri(@uri)
20+
@client = MongoReplicaSetClient.from_uri(@uri, :op_timeout => TEST_OP_TIMEOUT)
2121
@db = @client.db(TEST_DB)
2222
@coll = @db.collection("test-sets")
2323
@coll.insert({:a => 1})

0 commit comments

Comments
 (0)