view tests/lockdelay.py @ 35782:9d249f3de730

wireproto: don't compress errors from getbundle() Errors should be small. There's no real need to compress them. Truth be told, there's no good reason to not compress them either. But leaving them uncompressed makes it easier to test failures by looking at the raw HTTP response. This makes it easier for us to write tests. It may make it easier for people writing their own clients. Differential Revision: https://phab.mercurial-scm.org/D1922
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 20 Jan 2018 15:43:02 -0800
parents a76d5ba7ac43
children 2372284d9457
line wrap: on
line source

# 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):
            delay = float(os.environ.get('HGPRELOCKDELAY', '0.0'))
            if delay:
                time.sleep(delay)
            res = super(delayedlockrepo, self).lock()
            delay = float(os.environ.get('HGPOSTLOCKDELAY', '0.0'))
            if delay:
                time.sleep(delay)
            return res
    repo.__class__ = delayedlockrepo