tests/lockdelay.py
author Pulkit Goyal <7895pulkit@gmail.com>
Sun, 03 Jul 2016 22:28:24 +0530
changeset 29485 6a98f9408a50
parent 28289 d493d64757eb
child 30068 a76d5ba7ac43
permissions -rw-r--r--
py3: make files use absolute_import and print_function This patch includes addition of absolute_import and print_function to the files where they are missing. The modern importing conventions are also followed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28289
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     1
# Dummy extension that adds a delay after acquiring a lock.
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
#
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
# This extension can be used to test race conditions between lock acquisition.
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
from __future__ import absolute_import
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     7
import os
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     8
import time
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     9
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    10
from mercurial import (
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    11
    lock as lockmod,
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    12
)
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    13
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    14
class delaylock(lockmod.lock):
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    15
    def lock(self):
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    16
        delay = float(os.environ.get('HGPRELOCKDELAY', '0.0'))
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    17
        if delay:
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    18
            time.sleep(delay)
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    19
        res = super(delaylock, self).lock()
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    20
        delay = float(os.environ.get('HGPOSTLOCKDELAY', '0.0'))
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    21
        if delay:
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    22
            time.sleep(delay)
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    23
        return res
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    24
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    25
def extsetup(ui):
d493d64757eb hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    26
    lockmod.lock = delaylock