Mercurial > hg
comparison mercurial/testing/__init__.py @ 46984:99c629101b73
testing: add a utility function to wait for file create
This is similar to `tests/testlib/wait-on-file`, but for the python code
Differential Revision: https://phab.mercurial-scm.org/D10476
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 19 Apr 2021 19:10:18 +0200 |
parents | ae531f5e583c |
children | 52cee44aa1a0 |
comparison
equal
deleted
inserted
replaced
46983:e38718838808 | 46984:99c629101b73 |
---|---|
1 from __future__ import ( | |
2 absolute_import, | |
3 division, | |
4 ) | |
5 | |
6 import os | |
7 import time | |
8 | |
9 | |
10 # work around check-code complains | |
11 # | |
12 # This is a simple log level module doing simple test related work, we can't | |
13 # import more things, and we do not need it. | |
14 environ = getattr(os, 'environ') | |
15 | |
16 | |
17 def _timeout_factor(): | |
18 """return the current modification to timeout""" | |
19 default = int(environ.get('HGTEST_TIMEOUT_DEFAULT', 1)) | |
20 current = int(environ.get('HGTEST_TIMEOUT', default)) | |
21 return current / float(default) | |
22 | |
23 | |
24 def wait_file(path, timeout=10): | |
25 timeout *= _timeout_factor() | |
26 start = time.time() | |
27 while not os.path.exists(path): | |
28 if time.time() - start > timeout: | |
29 raise RuntimeError(b"timed out waiting for file: %s" % path) | |
30 time.sleep(0.01) |