Mercurial > hg
annotate tests/lockdelay.py @ 42742:334c1ea57136
discovery: new devel.discovery.randomize option
By default, this is True, but setting it to False is a uniform
way to kill all randomness in integration tests such as test-setdiscovery.t
By "uniform" we mean that it can be passed to implementations in other
languages, for which the monkey-patching of random.sample would be
irrelevant.
In the above mentioned test file, we use it right away,
replacing the adhoc extension that had the same purpose, and to derandomize a
case with many round-trips, that we'll need to behave uniformly in the Rust
version.
Differential Revision: https://phab.mercurial-scm.org/D6427
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Tue, 21 May 2019 17:44:15 +0200 |
parents | a76d5ba7ac43 |
children | 2372284d9457 |
rev | line source |
---|---|
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 |
30068
a76d5ba7ac43
pull: grab wlock during pull
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28289
diff
changeset
|
10 def reposetup(ui, repo): |
28289
d493d64757eb
hg: obtain lock when creating share from pooled repo (issue5104)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 |
30068
a76d5ba7ac43
pull: grab wlock during pull
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28289
diff
changeset
|
12 class delayedlockrepo(repo.__class__): |
a76d5ba7ac43
pull: grab wlock during pull
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28289
diff
changeset
|
13 def lock(self): |
a76d5ba7ac43
pull: grab wlock during pull
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28289
diff
changeset
|
14 delay = float(os.environ.get('HGPRELOCKDELAY', '0.0')) |
a76d5ba7ac43
pull: grab wlock during pull
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28289
diff
changeset
|
15 if delay: |
a76d5ba7ac43
pull: grab wlock during pull
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28289
diff
changeset
|
16 time.sleep(delay) |
a76d5ba7ac43
pull: grab wlock during pull
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28289
diff
changeset
|
17 res = super(delayedlockrepo, self).lock() |
a76d5ba7ac43
pull: grab wlock during pull
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28289
diff
changeset
|
18 delay = float(os.environ.get('HGPOSTLOCKDELAY', '0.0')) |
a76d5ba7ac43
pull: grab wlock during pull
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28289
diff
changeset
|
19 if delay: |
a76d5ba7ac43
pull: grab wlock during pull
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28289
diff
changeset
|
20 time.sleep(delay) |
a76d5ba7ac43
pull: grab wlock during pull
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28289
diff
changeset
|
21 return res |
a76d5ba7ac43
pull: grab wlock during pull
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
28289
diff
changeset
|
22 repo.__class__ = delayedlockrepo |