From 59e3b9b8e799ee265608e189c41b1926be9216b5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 28 2018 14:23:06 +0000 Subject: Increase the number of file descriptors we allow while running the tests Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/__init__.py b/tests/__init__.py index 4b355de..1cacf22 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -12,14 +12,15 @@ __requires__ = ['SQLAlchemy >= 0.7'] import pkg_resources import logging -import unittest +import os +import re +import resource import shutil import subprocess import sys import tempfile import time -import re -import os +import unittest logging.basicConfig(stream=sys.stderr) # Always enable performance counting for tests @@ -72,6 +73,7 @@ DB_URL = '%(dburl)s' ALLOW_PROJECT_DOWAIT = True DEBUG = True """ +MAX_NOFILE = 4096 LOG.info('BUILD_ID: %s', os.environ.get('BUILD_ID')) @@ -141,7 +143,6 @@ def user_set(APP, user): with appcontext_pushed.connected_to(handler, APP): yield - # In order to save time during local test execution, we create sqlite DB file # only once and then we use a fresh copy of it for every test case (as opposed # to creating DB file for every test case). @@ -185,6 +186,8 @@ def _create_db_entities(dbpath): def setUp(): + set_rlimit_nofiles() + if DB_PATH: return @@ -196,6 +199,23 @@ def tearDown(): os.unlink(dbfile) +def set_rlimit_nofiles(limit=MAX_NOFILE): + try: + msg = u'Setting RLIMIT_NOFILE to {max_files}'.format( + max_files=limit) + LOG.info(msg) + resource.setrlimit( + resource.RLIMIT_NOFILE, (limit, limit)) + except (resource.error, ValueError) as e: + msg = u'Failed to raise the limit on the maximum number of ' \ + u'open file descriptors to {max_files}: {err}' + LOG.warning(msg.format(max_files=limit, err=str(e))) + finally: + nofile = resource.getrlimit(resource.RLIMIT_NOFILE) + LOG.info( + u'RLIMIT_NOFILE is set to {nofile}'.format(nofile=nofile)) + + class SimplePagureTest(unittest.TestCase): """ Simple Test class that does not set a broker/worker