Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions test/asynchronous/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
CollectionInvalid,
ConfigurationError,
ConnectionFailure,
ExecutionTimeout,
InvalidOperation,
NetworkTimeout,
OperationFailure,
PyMongoError,
)
from pymongo.operations import IndexModel, InsertOne
from pymongo.read_concern import ReadConcern
Expand Down Expand Up @@ -608,8 +608,13 @@ async def callback(session):
listener.reset()
async with client.start_session() as s:
with pymongo.timeout(1.0):
with self.assertRaises(ExecutionTimeout):
# The server may report MaxTimeMSExpired as an
# ExecutionTimeout or a WriteError.
# The driver can also time out with a NetworkTimeout while waiting for a response,
# so only assert that the error is a CSOT timeout.
with self.assertRaises(PyMongoError) as ctx:
await s.with_transaction(callback)
self.assertTrue(ctx.exception.timeout)

# At least two attempts: the original and one or more retries.
inserts = len([x for x in listener.started_command_names() if x == "insert"])
Expand Down
9 changes: 7 additions & 2 deletions test/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
CollectionInvalid,
ConfigurationError,
ConnectionFailure,
ExecutionTimeout,
InvalidOperation,
NetworkTimeout,
OperationFailure,
PyMongoError,
)
from pymongo.operations import IndexModel, InsertOne
from pymongo.read_concern import ReadConcern
Expand Down Expand Up @@ -596,8 +596,13 @@ def callback(session):
listener.reset()
with client.start_session() as s:
with pymongo.timeout(1.0):
with self.assertRaises(ExecutionTimeout):
# The server may report MaxTimeMSExpired as an
# ExecutionTimeout or a WriteError.
# The driver can also time out with a NetworkTimeout while waiting for a response,
# so only assert that the error is a CSOT timeout.
with self.assertRaises(PyMongoError) as ctx:
s.with_transaction(callback)
self.assertTrue(ctx.exception.timeout)

# At least two attempts: the original and one or more retries.
inserts = len([x for x in listener.started_command_names() if x == "insert"])
Expand Down
Loading