Skip to content
Browse files

Add more tests for maxTimeMS PYTHON-550

  • Loading branch information...
1 parent 502b7d4 commit 22caa27a7297082b95a16afc797246eb93ffb466 @behackett behackett committed Mar 4, 2014
Showing with 46 additions and 11 deletions.
  1. +14 −9 test/test_cursor.py
  2. +32 −2 test/test_database.py
View
23 test/test_cursor.py
@@ -102,19 +102,24 @@ def test_max_time_ms(self):
self.assertTrue(coll.find_one(max_time_ms=1000))
- reducer = Code("""function(obj, prev){prev.count++;}""")
- coll.group(key={"amalia": 1}, condition={}, initial={"count": 0},
- reduce=reducer, maxTimeMS=1000)
-
if "enableTestCommands=1" in get_command_line(self.client)["argv"]:
self.client.admin.command("configureFailPoint",
"maxTimeAlwaysTimeOut",
mode="alwaysOn")
- self.assertRaises(ExecutionTimeout,
- coll.find_one, max_time_ms=1)
- self.client.admin.command("configureFailPoint",
- "maxTimeAlwaysTimeOut",
- mode="off")
+ try:
+ cursor = coll.find().max_time_ms(1)
+ try:
+ cursor.next()
+ except ExecutionTimeout:
+ pass
+ else:
+ self.fail("ExecutionTimeout not raised")
+ self.assertRaises(ExecutionTimeout,
+ coll.find_one, max_time_ms=1)
+ finally:
+ self.client.admin.command("configureFailPoint",
+ "maxTimeAlwaysTimeOut",
+ mode="off")
def test_explain(self):
a = self.db.test.find()
View
34 test/test_database.py
@@ -40,14 +40,15 @@
from pymongo.database import Database
from pymongo.errors import (CollectionInvalid,
ConfigurationError,
+ ExecutionTimeout,
InvalidName,
OperationFailure)
from pymongo.son_manipulator import (AutoReference,
NamespaceInjector,
ObjectIdShuffler)
from test import version
-from test.utils import (is_mongos, server_started_with_auth,
- remove_all_users)
+from test.utils import (get_command_line, is_mongos,
+ remove_all_users, server_started_with_auth)
from test.test_client import get_client
@@ -959,6 +960,35 @@ def test_command_read_pref_warning(self):
warnings.resetwarnings()
warnings.simplefilter("ignore")
+ def test_command_max_time_ms(self):
+ if not version.at_least(self.client, (2, 5, 3, -1)):
+ raise SkipTest("MaxTimeMS requires MongoDB >= 2.5.3")
+ if "enableTestCommands=1" not in get_command_line(self.client)["argv"]:
+ raise SkipTest("Test commands must be enabled.")
+
+ self.client.admin.command("configureFailPoint",
+ "maxTimeAlwaysTimeOut",
+ mode="alwaysOn")
+ try:
+ db = self.client.pymongo_test
+ db.command('count', 'test')
+ self.assertRaises(ExecutionTimeout, db.command,
+ 'count', 'test', maxTimeMS=1)
+ pipeline = [{'$project': {'name': 1, 'count': 1}}]
+ # Database command helper.
+ db.command('aggregate', 'test', pipeline=pipeline)
+ self.assertRaises(ExecutionTimeout, db.command,
+ 'aggregate', 'test',
+ pipeline=pipeline, maxTimeMS=1)
+ # Collection helper.
+ db.test.aggregate(pipeline=pipeline)
+ self.assertRaises(ExecutionTimeout,
+ db.test.aggregate, pipeline, maxTimeMS=1)
+ finally:
+ self.client.admin.command("configureFailPoint",
+ "maxTimeAlwaysTimeOut",
+ mode="off")
+
if __name__ == "__main__":
unittest.main()

0 comments on commit 22caa27

Please sign in to comment.
Something went wrong with that request. Please try again.