Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit be49dbc

Browse files
committed
updated tests
1 parent 4cffec3 commit be49dbc

1 file changed

Lines changed: 27 additions & 22 deletions

File tree

tests/system/test_transaction.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -148,46 +148,51 @@ def test_failure_with_contention(datastore_client, entities_to_delete, database_
148148

149149
entities_to_delete.append(orig_entity)
150150

151-
with pytest.raises(Conflict):
152-
with local_client.transaction() as txn:
153-
entity_in_txn = local_client.get(key)
151+
with local_client.transaction() as txn:
152+
entity_in_txn = local_client.get(key)
154153

155-
# Update the original entity outside the transaction.
156-
orig_entity[contention_prop_name] = "outside"
154+
# Update the original entity outside the transaction.
155+
orig_entity[contention_prop_name] = "outside"
156+
with pytest.raises(Conflict):
157157
datastore_client.put(orig_entity)
158158

159-
# Try to update the entity which we already updated outside the
160-
# transaction.
161-
entity_in_txn[contention_prop_name] = "inside"
162-
txn.put(entity_in_txn)
159+
# Try to update the entity which we already updated outside the
160+
# transaction.
161+
entity_in_txn[contention_prop_name] = "inside"
162+
txn.put(entity_in_txn)
163+
# now that transaction is complete, should be able to update outside
164+
datastore_client.put(orig_entity)
163165

164166

165167
@pytest.mark.parametrize("database_id", [None, _helpers.TEST_DATABASE], indirect=True)
166-
def test_failure_with_contention_no_context_manager(datastore_client, entities_to_delete):
168+
def test_failure_with_contention_no_context_manager(datastore_client, entities_to_delete, database_id):
167169
contention_prop_name = "baz"
168170
local_client = _helpers.clone_client(datastore_client)
169171

170172
# Insert an entity which will be retrieved in a transaction
171173
# and updated outside it with a contentious value.
172-
key = local_client.key("BreakTxn", 1234)
174+
key = local_client.key("BreakTxnCM3", 1234)
173175
orig_entity = datastore.Entity(key=key)
174176
orig_entity["foo"] = "bar"
175177
local_client.put(orig_entity)
176178

177179
entities_to_delete.append(orig_entity)
178180

179-
with pytest.raises(Conflict):
180-
txn = local_client.transaction()
181-
txn.begin()
181+
txn = local_client.transaction()
182+
txn.begin()
182183

183-
entity_in_txn = local_client.get(key)
184+
entity_in_txn = local_client.get(key, transaction=txn)
184185

185-
# Update the original entity outside the transaction.
186-
orig_entity[contention_prop_name] = "outside"
186+
# Update the original entity outside the transaction.
187+
# should fail due to contention
188+
orig_entity[contention_prop_name] = "outside"
189+
with pytest.raises(Conflict):
187190
datastore_client.put(orig_entity)
188191

189-
# Try to update the entity which we already updated outside the
190-
# transaction.
191-
entity_in_txn[contention_prop_name] = "inside"
192-
txn.put(entity_in_txn)
193-
txn.commit()
192+
# Try to update the entity inside the transaction
193+
entity_in_txn[contention_prop_name] = "inside"
194+
txn.put(entity_in_txn)
195+
txn.commit()
196+
197+
# now that transaction is complete, should be able to update outside
198+
datastore_client.put(orig_entity)

0 commit comments

Comments
 (0)