X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/55aafbb07904ca24390dd47ea960eae7cb2b909a..HEAD:/services/fuse/tests/integration_test.py diff --git a/services/fuse/tests/integration_test.py b/services/fuse/tests/integration_test.py index 6a0c5de899..24ac7baf04 100644 --- a/services/fuse/tests/integration_test.py +++ b/services/fuse/tests/integration_test.py @@ -11,18 +11,17 @@ import inspect import logging import multiprocessing import os -import run_test_server import signal import sys import tempfile import unittest -_pool = None +import pytest +from . import run_test_server @atexit.register def _pool_cleanup(): - global _pool if _pool is None: return _pool.close() @@ -36,6 +35,17 @@ def wrap_static_test_method(modName, clsName, funcName, args, kwargs): Test().runTest(*args, **kwargs) +# To avoid Python's threading+multiprocessing=deadlock problems, we +# use a single global pool with maxtasksperchild=None for the entire +# test suite. +_pool = None +def workerPool(): + global _pool + if _pool is None: + _pool = multiprocessing.Pool(processes=1, maxtasksperchild=None) + return _pool + + class IntegrationTest(unittest.TestCase): def pool_test(self, *args, **kwargs): """Run a static method as a unit test, in a different process. @@ -43,20 +53,17 @@ class IntegrationTest(unittest.TestCase): If called by method 'foobar', the static method '_foobar' of the same class will be called in the other process. """ - global _pool - if _pool is None: - _pool = multiprocessing.Pool(1, maxtasksperchild=1) modName = inspect.getmodule(self).__name__ clsName = self.__class__.__name__ funcName = inspect.currentframe().f_back.f_code.co_name - _pool.apply( + workerPool().apply( wrap_static_test_method, (modName, clsName, '_'+funcName, args, kwargs)) @classmethod def setUpClass(cls): run_test_server.run() - run_test_server.run_keep(enforce_permissions=True, num_servers=2) + run_test_server.run_keep(blob_signing=True, num_servers=2) @classmethod def tearDownClass(cls): @@ -81,14 +88,20 @@ class IntegrationTest(unittest.TestCase): with arvados_fuse.command.Mount( arvados_fuse.command.ArgumentParser().parse_args( argv + ['--foreground', - '--unmount-timeout=2', + '--unmount-timeout=60', self.mnt])) as self.mount: return func(self, *args, **kwargs) finally: if self.mount and self.mount.llfuse_thread.is_alive(): - logging.warning("IntegrationTest.mount:" - " llfuse thread still alive after umount" - " -- killing test suite to avoid deadlock") - os.kill(os.getpid(), signal.SIGKILL) + # pytest uses exit status 2 when test collection failed. + # A UnitTest failing in setup/teardown counts as a + # collection failure, so pytest will exit with status 2 + # no matter what status you specify here. run-tests.sh + # looks for this status, so specify 2 just to keep + # everything as consistent as possible. + # TODO: If we refactor these tests so they're not built + # on unittest, consider using a dedicated, non-pytest + # exit code like TEMPFAIL. + pytest.exit("llfuse thread outlived test - aborting test suite to avoid deadlock", 2) return wrapper return decorator