Test that two concurrent transactions from same thread work with different refs.
(testrepo: Repository)
| 277 | |
| 278 | |
| 279 | def 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 | |
| 307 | def test_transaction_nested_same_ref_conflict(testrepo: Repository) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…