tests/lockdelay.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Mon, 21 Dec 2020 11:15:45 +0100
changeset 46622 8fcf07e6bbb4
parent 45455 f6c67bb4ca03
child 48966 6000f5b25c9b
permissions -rw-r--r--
copies-rust: make more use of the new comparison property We deal with the "both are the same" sooner and simplify the rest of the conditional. Differential Revision: https://phab.mercurial-scm.org/D9654

# Dummy extension that adds a delay after acquiring a lock.
#
# This extension can be used to test race conditions between lock acquisition.

from __future__ import absolute_import

import os
import time


def reposetup(ui, repo):
    class delayedlockrepo(repo.__class__):
        def lock(self, wait=True):
            delay = float(os.environ.get('HGPRELOCKDELAY', '0.0'))
            if delay:
                time.sleep(delay)
            res = super(delayedlockrepo, self).lock(wait=wait)
            delay = float(os.environ.get('HGPOSTLOCKDELAY', '0.0'))
            if delay:
                time.sleep(delay)
            return res

    repo.__class__ = delayedlockrepo