Set max open files the same way runtests.py does it

This commit is contained in:
Pedro Algarvio 2018-12-14 12:58:12 +00:00
parent d85baaef97
commit 67a62a77d2
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF

View file

@ -197,6 +197,63 @@ def pytest_configure(config):
)
# Make sure the test suite "knows" this is a pytest test run
RUNTIME_VARS.PYTEST_SESSION = True
def set_max_open_files_limits(min_soft=3072, min_hard=4096):
# Get current limits
if salt.utils.platform.is_windows():
import win32file
prev_hard = win32file._getmaxstdio()
prev_soft = 512
else:
import resource
prev_soft, prev_hard = resource.getrlimit(resource.RLIMIT_NOFILE)
# Check minimum required limits
set_limits = False
if prev_soft < min_soft:
soft = min_soft
set_limits = True
else:
soft = prev_soft
if prev_hard < min_hard:
hard = min_hard
set_limits = True
else:
hard = prev_hard
# Increase limits
if set_limits:
log.debug(
' * Max open files settings is too low (soft: %s, hard: %s) for running the tests. '
'Trying to raise the limits to soft: %s, hard: %s',
prev_soft,
prev_hard,
soft,
hard
)
try:
if salt.utils.platform.is_windows():
hard = 2048 if hard > 2048 else hard
win32file._setmaxstdio(hard)
else:
resource.setrlimit(resource.RLIMIT_NOFILE, (soft, hard))
except Exception as err:
log.error(
'Failed to raise the max open files settings -> %s. Please issue the following command '
'on your console: \'ulimit -u %s\'',
err,
soft,
)
exit(1)
return soft, hard
def pytest_report_header():
soft, hard = set_max_open_files_limits()
return 'max open files; soft: {}; hard: {}'.format(soft, hard)
# <---- Register Markers ---------------------------------------------------------------------------------------------