Show More
@@ -1,30 +1,35 b'' | |||
|
1 | 1 | from __future__ import ( |
|
2 | 2 | absolute_import, |
|
3 | 3 | division, |
|
4 | 4 | ) |
|
5 | 5 | |
|
6 | 6 | import os |
|
7 | 7 | import time |
|
8 | 8 | |
|
9 | 9 | |
|
10 | 10 | # work around check-code complains |
|
11 | 11 | # |
|
12 | 12 | # This is a simple log level module doing simple test related work, we can't |
|
13 | 13 | # import more things, and we do not need it. |
|
14 | 14 | environ = getattr(os, 'environ') |
|
15 | 15 | |
|
16 | 16 | |
|
17 | 17 | def _timeout_factor(): |
|
18 | 18 | """return the current modification to timeout""" |
|
19 | 19 | default = int(environ.get('HGTEST_TIMEOUT_DEFAULT', 1)) |
|
20 | 20 | current = int(environ.get('HGTEST_TIMEOUT', default)) |
|
21 | 21 | return current / float(default) |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | def wait_file(path, timeout=10): |
|
25 | 25 | timeout *= _timeout_factor() |
|
26 | 26 | start = time.time() |
|
27 | 27 | while not os.path.exists(path): |
|
28 | 28 | if time.time() - start > timeout: |
|
29 | 29 | raise RuntimeError(b"timed out waiting for file: %s" % path) |
|
30 | 30 | time.sleep(0.01) |
|
31 | ||
|
32 | ||
|
33 | def write_file(path, content=b''): | |
|
34 | with open(path, 'wb') as f: | |
|
35 | f.write(content) |
General Comments 0
You need to be logged in to leave comments.
Login now