MCPcopy Create free account
hub / github.com/libgit2/pygit2 / test_transaction_nested_same_thread

Function test_transaction_nested_same_thread

test/test_transaction.py:279–304  ·  view source on GitHub ↗

Test that two concurrent transactions from same thread work with different refs.

(testrepo: Repository)

Source from the content-addressed store, hash-verified

277
278
279def test_transaction_nested_same_thread(testrepo: Repository) -> None:
280 """Test that two concurrent transactions from same thread work with different refs."""
281 # Create test refs
282 ref1_name = 'refs/heads/nested-test-1'
283 ref2_name = 'refs/heads/nested-test-2'
284 target1 = Oid(hex='5ebeeebb320790caf276b9fc8b24546d63316533')
285 target2 = Oid(hex='2be5719152d4f82c7302b1c0932d8e5f0a4a0e98')
286 testrepo.create_reference(ref1_name, target1)
287 testrepo.create_reference(ref2_name, target2)
288
289 # Nested transactions should work as long as they don't conflict
290 with testrepo.transaction() as txn1:
291 txn1.lock_ref(ref1_name)
292
293 with testrepo.transaction() as txn2:
294 txn2.lock_ref(ref2_name)
295 txn2.set_target(ref2_name, target1, message='Inner transaction')
296
297 # Inner transaction committed, now update outer
298 txn1.set_target(ref1_name, target2, message='Outer transaction')
299
300 # Both updates should have been applied
301 ref1 = testrepo.lookup_reference(ref1_name)
302 ref2 = testrepo.lookup_reference(ref2_name)
303 assert str(ref1.target) == '2be5719152d4f82c7302b1c0932d8e5f0a4a0e98'
304 assert str(ref2.target) == '5ebeeebb320790caf276b9fc8b24546d63316533'
305
306
307def test_transaction_nested_same_ref_conflict(testrepo: Repository) -> None:

Callers

nothing calls this directly

Calls 4

create_referenceMethod · 0.80
transactionMethod · 0.80
lock_refMethod · 0.80
set_targetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…