From 59e3b9b8e799ee265608e189c41b1926be9216b5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 28 2018 14:23:06 +0000 Subject: [PATCH 1/3] 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 From 2c9f940294f4ad2f15d5e07aa6335d81c04653bc Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 28 2018 14:23:06 +0000 Subject: [PATCH 2/3] Fix flake8 error Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/pagure_ci.py b/pagure/hooks/pagure_ci.py index ac1d64c..b1c8cc6 100644 --- a/pagure/hooks/pagure_ci.py +++ b/pagure/hooks/pagure_ci.py @@ -80,7 +80,8 @@ The URL to be used to POST the results of your build is: {% else %} You will have access to the token used by the CI service to trigger the job -and the URL needed to report back the job status in pagure after the plugin activation. +and the URL needed to report back the job status in pagure after the plugin +activation. {% endif %} """ From 2d5c524b8674851c6d2f8eedd341a1f24fa3576e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 28 2018 14:23:06 +0000 Subject: [PATCH 3/3] Document the method bumping the number of allowed file descriptors Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/__init__.py b/tests/__init__.py index 1cacf22..0d2c83f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -200,20 +200,32 @@ def tearDown(): 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)) + """ + Change the number of file descriptors allowed for this process, from + 1024 (the default) to the specified number. + + The test suite is leaking file descriptors, socket and a few others but + we haven't managed to find the root cause so far, maybe in celery, + maybe somewhere else :( + In the mean time we're increasing the limit, it's very much a bandage + in a wooden leg but at least it allows us to keep running the entire + test suite. + + """ + 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):