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
24 changes: 24 additions & 0 deletions test/asynchronous/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,5 +578,29 @@ async def callback(session):
self.assertFalse(s.in_transaction)


class TestOptionsInsideTransactionProse(AsyncTransactionsBase):
@async_client_context.require_transactions
@async_client_context.require_no_standalone
async def test_case_1(self):
# Write concern not inherited from collection object inside transaction
# Create a MongoClient running against a configured sharded/replica set/load balanced cluster.
client = async_client_context.client
coll = client[self.db.name].test
await coll.delete_many({})
# Start a new session on the client.
async with client.start_session() as s:
# Start a transaction on the session.
await s.start_transaction()
# Instantiate a collection object in the driver with a default write concern of { w: 0 }.
inner_coll = coll.with_options(write_concern=WriteConcern(w=0))
# Insert the document { n: 1 } on the instantiated collection.
result = await inner_coll.insert_one({"n": 1}, session=s)
# Commit the transaction.
await s.commit_transaction()
# End the session.
# Ensure the document was inserted and no error was thrown from the transaction.
assert result.inserted_id is not None


if __name__ == "__main__":
unittest.main()
24 changes: 24 additions & 0 deletions test/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,5 +566,29 @@ def callback(session):
self.assertFalse(s.in_transaction)


class TestOptionsInsideTransactionProse(TransactionsBase):
@client_context.require_transactions
@client_context.require_no_standalone
def test_case_1(self):
# Write concern not inherited from collection object inside transaction
# Create a MongoClient running against a configured sharded/replica set/load balanced cluster.
client = client_context.client
coll = client[self.db.name].test
coll.delete_many({})
# Start a new session on the client.
with client.start_session() as s:
# Start a transaction on the session.
s.start_transaction()
# Instantiate a collection object in the driver with a default write concern of { w: 0 }.
inner_coll = coll.with_options(write_concern=WriteConcern(w=0))
# Insert the document { n: 1 } on the instantiated collection.
result = inner_coll.insert_one({"n": 1}, session=s)
# Commit the transaction.
s.commit_transaction()
# End the session.
# Ensure the document was inserted and no error was thrown from the transaction.
assert result.inserted_id is not None


if __name__ == "__main__":
unittest.main()
Loading