sapling/eden/scm/tests/test-nested-lock.py
Jun Wu 0498f87da1 lock: detect deadlock in a same process
Summary:
This is for cases like:

    repo1 = hg.repository(path)
    repo2 = hg.repository(path)  # same path
    with repo1.lock():
        repo2.lock()  # deadlock

Previously it simply deadlocks with confusing message:

    waiting for lock held by process X  # X is the current process

With this change it will raise a ProgrammingError about deadlock.

Reviewed By: DurhamG

Differential Revision: D24214458

fbshipit-source-id: 57faddaed6d2f1d36fab067c2e1f63b3cda0a1fe
2020-10-19 17:07:30 -07:00

28 lines
696 B
Python

# Copyright (c) Facebook, Inc. and its affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.
from testutil.dott import feature, sh, testtmp # noqa: F401
feature.require(["no-windows"])
def test_nested_lock():
from edenscm.mercurial import hg, ui as uimod
ui = uimod.ui.load()
repo1 = hg.repository(ui, testtmp.TESTTMP, create=True)
repo2 = hg.repository(ui, testtmp.TESTTMP)
# repo2.lock() should detect deadlock.
try:
with repo1.lock(), repo2.lock(wait=False):
pass
except Exception as ex:
msg = str(ex)
assert "deadlock" in msg
test_nested_lock()