comparison mercurial/testing/__init__.py @ 50214:8e0d823ef182 stable

testing: introduce util function to synchronize concurrent commands on files This is an extension of mechanisms that the tests have been using for a while. To be able to also control the execution in Rust, we introduce utility to perform such `wait_on_file` logic based on some configuration value. This will be used in the tests introduced in the next changesets.
author Raphaël Gomès <rgomes@octobus.net>
date Tue, 28 Feb 2023 00:01:41 +0100
parents 6000f5b25c9b
children f4733654f144
comparison
equal deleted inserted replaced
50211:f5e4248e5bce 50214:8e0d823ef182
5 # work around check-code complains 5 # work around check-code complains
6 # 6 #
7 # This is a simple log level module doing simple test related work, we can't 7 # This is a simple log level module doing simple test related work, we can't
8 # import more things, and we do not need it. 8 # import more things, and we do not need it.
9 environ = getattr(os, 'environ') 9 environ = getattr(os, 'environ')
10
11
12 def wait_on_cfg(ui, cfg, timeout=10):
13 """synchronize on the `cfg` config path
14
15 Use this to synchronize commands during race tests.
16 """
17 full_config = b'sync.' + cfg
18 wait_config = full_config + b'-timeout'
19 sync_path = ui.config(b'devel', full_config)
20 if sync_path is not None:
21 timeout = ui.config(b'devel', wait_config)
22 ready_path = sync_path + b'.waiting'
23 write_file(ready_path)
24 wait_file(sync_path, timeout=timeout)
10 25
11 26
12 def _timeout_factor(): 27 def _timeout_factor():
13 """return the current modification to timeout""" 28 """return the current modification to timeout"""
14 default = int(environ.get('HGTEST_TIMEOUT_DEFAULT', 360)) 29 default = int(environ.get('HGTEST_TIMEOUT_DEFAULT', 360))