diff --git a/test/asynchronous/test_transactions.py b/test/asynchronous/test_transactions.py index 53eb4df6f7..2542da2faa 100644 --- a/test/asynchronous/test_transactions.py +++ b/test/asynchronous/test_transactions.py @@ -46,10 +46,10 @@ CollectionInvalid, ConfigurationError, ConnectionFailure, - ExecutionTimeout, InvalidOperation, NetworkTimeout, OperationFailure, + PyMongoError, ) from pymongo.operations import IndexModel, InsertOne from pymongo.read_concern import ReadConcern @@ -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"]) diff --git a/test/test_transactions.py b/test/test_transactions.py index acfe3d764a..c1a55af8ed 100644 --- a/test/test_transactions.py +++ b/test/test_transactions.py @@ -41,10 +41,10 @@ CollectionInvalid, ConfigurationError, ConnectionFailure, - ExecutionTimeout, InvalidOperation, NetworkTimeout, OperationFailure, + PyMongoError, ) from pymongo.operations import IndexModel, InsertOne from pymongo.read_concern import ReadConcern @@ -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"])