tests/lockdelay.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 01 Jun 2022 03:12:23 +0200
changeset 49268 7b0cf4517d82
parent 48875 6000f5b25c9b
permissions -rw-r--r--
mr-template: drop the "title and description" I though I would affect the template in the menu itself, however it just a normal piece of text that should not be here.

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


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