tests/lockdelay.py
branchstable
changeset 28289 d493d64757eb
child 30068 a76d5ba7ac43
equal deleted inserted replaced
28288:e417e4512b0f 28289:d493d64757eb
       
     1 # Dummy extension that adds a delay after acquiring a lock.
       
     2 #
       
     3 # This extension can be used to test race conditions between lock acquisition.
       
     4 
       
     5 from __future__ import absolute_import
       
     6 
       
     7 import os
       
     8 import time
       
     9 
       
    10 from mercurial import (
       
    11     lock as lockmod,
       
    12 )
       
    13 
       
    14 class delaylock(lockmod.lock):
       
    15     def lock(self):
       
    16         delay = float(os.environ.get('HGPRELOCKDELAY', '0.0'))
       
    17         if delay:
       
    18             time.sleep(delay)
       
    19         res = super(delaylock, self).lock()
       
    20         delay = float(os.environ.get('HGPOSTLOCKDELAY', '0.0'))
       
    21         if delay:
       
    22             time.sleep(delay)
       
    23         return res
       
    24 
       
    25 def extsetup(ui):
       
    26     lockmod.lock = delaylock