2012-04-03 19:40:38 +00:00
|
|
|
require './test/test_helper'
|
|
|
|
|
|
|
|
class TestTimeout < Test::Unit::TestCase
|
|
|
|
def test_op_timeout
|
2012-04-04 17:45:19 +00:00
|
|
|
connection = standard_connection(:op_timeout => 2)
|
2012-04-03 19:40:38 +00:00
|
|
|
|
2012-04-04 17:45:19 +00:00
|
|
|
admin = connection.db('admin')
|
2012-04-03 19:40:38 +00:00
|
|
|
|
2012-04-04 17:45:19 +00:00
|
|
|
command = BSON::OrderedHash.new
|
|
|
|
command[:sleep] = 1
|
|
|
|
command[:secs] = 1
|
|
|
|
# Should not timeout
|
|
|
|
assert admin.command(command)
|
|
|
|
|
|
|
|
# Should timeout
|
|
|
|
command[:secs] = 3
|
2012-04-03 19:40:38 +00:00
|
|
|
assert_raise Mongo::OperationTimeout do
|
2012-04-04 17:45:19 +00:00
|
|
|
admin.command(command)
|
2012-04-03 19:40:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
=begin
|
|
|
|
def test_ssl_op_timeout
|
|
|
|
connection = standard_connection(:op_timeout => 1, :ssl => true)
|
|
|
|
|
|
|
|
coll = connection.db(MONGO_TEST_DB).collection("test")
|
|
|
|
coll.insert({:a => 1})
|
|
|
|
|
|
|
|
# Should not timeout
|
|
|
|
assert coll.find_one({"$where" => "sleep(100); return true;"})
|
|
|
|
|
|
|
|
# Should timeout
|
|
|
|
assert_raise Mongo::OperationTimeout do
|
|
|
|
coll.find_one({"$where" => "sleep(5 * 1000); return true;"})
|
|
|
|
end
|
|
|
|
|
|
|
|
coll.remove
|
|
|
|
end
|
|
|
|
=end
|
|
|
|
end
|