tests/lockdelay.py
author Pulkit Goyal <7895pulkit@gmail.com>
Sat, 16 Apr 2016 04:06:24 +0530
changeset 28934 c4040a35b5d9
parent 28289 d493d64757eb
child 30068 a76d5ba7ac43
permissions -rw-r--r--
tests: make test-trusted use print_function There was some confusing output format at some places in test-trusted.py.out, the new print function ends with a newline by default whereas the old print statement uses a space generally. So the output in test-trusted.py.out is changed because of some confusing output format which was produced by print statement
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