comparison tests/run-tests.py @ 49234:9dad328434c7 stable

tests: work around non-thread-safeness of sysconfig.get_config_var()
author Manuel Jacob <me@manueljacob.de>
date Sun, 29 May 2022 14:44:19 +0200
parents 8d31ef3017c9
children cd51d4957b28
comparison
equal deleted inserted replaced
49216:9ea9445c3223 49234:9dad328434c7
998 import killdaemons as killmod 998 import killdaemons as killmod
999 999
1000 return killmod.killdaemons(pidfile, tryhard=False, remove=True, logfn=vlog) 1000 return killmod.killdaemons(pidfile, tryhard=False, remove=True, logfn=vlog)
1001 1001
1002 1002
1003 # sysconfig is not thread-safe (https://github.com/python/cpython/issues/92452)
1004 sysconfiglock = threading.Lock()
1005
1006
1003 class Test(unittest.TestCase): 1007 class Test(unittest.TestCase):
1004 """Encapsulates a single, runnable test. 1008 """Encapsulates a single, runnable test.
1005 1009
1006 While this class conforms to the unittest.TestCase API, it differs in that 1010 While this class conforms to the unittest.TestCase API, it differs in that
1007 instances need to be instantiated manually. (Typically, unittest.TestCase 1011 instances need to be instantiated manually. (Typically, unittest.TestCase
1428 def defineport(i): 1432 def defineport(i):
1429 offset = '' if i == 0 else '%s' % i 1433 offset = '' if i == 0 else '%s' % i
1430 env["HGPORT%s" % offset] = '%s' % (self._startport + i) 1434 env["HGPORT%s" % offset] = '%s' % (self._startport + i)
1431 1435
1432 env = os.environ.copy() 1436 env = os.environ.copy()
1433 env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') or '' 1437 with sysconfiglock:
1438 env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') or ''
1434 env['HGEMITWARNINGS'] = '1' 1439 env['HGEMITWARNINGS'] = '1'
1435 env['TESTTMP'] = _bytes2sys(self._testtmp) 1440 env['TESTTMP'] = _bytes2sys(self._testtmp)
1436 # the FORWARD_SLASH version is useful when running `sh` on non unix 1441 # the FORWARD_SLASH version is useful when running `sh` on non unix
1437 # system (e.g. Windows) 1442 # system (e.g. Windows)
1438 env['TESTTMP_FORWARD_SLASH'] = env['TESTTMP'].replace(os.sep, '/') 1443 env['TESTTMP_FORWARD_SLASH'] = env['TESTTMP'].replace(os.sep, '/')