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

Function test_transaction_commit_from_wrong_thread

test/test_transaction.py:255–276  ·  view source on GitHub ↗

Test that committing a transaction from wrong thread raises error.

(testrepo: Repository)

Source from the content-addressed store, hash-verified

253
254
255def test_transaction_commit_from_wrong_thread(testrepo: Repository) -> None:
256 """Test that committing a transaction from wrong thread raises error."""
257 txn: ReferenceTransaction | None = None
258
259 def create_transaction() -> None:
260 nonlocal txn
261 txn = testrepo.transaction().__enter__()
262 ref_name = 'refs/heads/wrong-thread-test'
263 target = Oid(hex='5ebeeebb320790caf276b9fc8b24546d63316533')
264 testrepo.create_reference(ref_name, target)
265 txn.lock_ref(ref_name)
266
267 # Create transaction in thread 1
268 thread = threading.Thread(target=create_transaction)
269 thread.start()
270 thread.join()
271
272 assert txn is not None
273 with pytest.raises(RuntimeError):
274 # Try to commit from main thread (different from creator) doesn't cause libgit2 to crash,
275 # it raises an exception instead
276 txn.commit()
277
278
279def test_transaction_nested_same_thread(testrepo: Repository) -> None:

Callers

nothing calls this directly

Calls 1

commitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…