X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/19ae770973482257117fe8ded5619c3018c4b60f..bffd1e4ee8532992b3790e4f232804a6731a9685:/services/fuse/tests/integration_test.py diff --git a/services/fuse/tests/integration_test.py b/services/fuse/tests/integration_test.py index 5a45bfc103..ba9cd88eb7 100644 --- a/services/fuse/tests/integration_test.py +++ b/services/fuse/tests/integration_test.py @@ -1,14 +1,34 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + import arvados import arvados_fuse import arvados_fuse.command +import atexit import functools import inspect +import llfuse +import logging import multiprocessing import os +import run_test_server +import signal import sys import tempfile import unittest -import run_test_server + +_pool = None + + +@atexit.register +def _pool_cleanup(): + global _pool + if _pool is None: + return + _pool.close() + _pool.join() + def wrap_static_test_method(modName, clsName, funcName, args, kwargs): class Test(unittest.TestCase): @@ -24,17 +44,15 @@ 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 = multiprocessing.Pool(1) - try: - pool.apply( - wrap_static_test_method, - (modName, clsName, '_'+funcName, args, kwargs)) - finally: - pool.terminate() - pool.join() + _pool.apply( + wrap_static_test_method, + (modName, clsName, '_'+funcName, args, kwargs)) @classmethod def setUpClass(cls): @@ -48,7 +66,6 @@ class IntegrationTest(unittest.TestCase): def setUp(self): self.mnt = tempfile.mkdtemp() run_test_server.authorize_with('active') - self.api = arvados.safeapi.ThreadSafeApiCache(arvados.config.settings()) def tearDown(self): os.rmdir(self.mnt) @@ -60,11 +77,23 @@ class IntegrationTest(unittest.TestCase): def decorator(func): @functools.wraps(func) def wrapper(self, *args, **kwargs): - with arvados_fuse.command.Mount( - arvados_fuse.command.ArgumentParser().parse_args( - argv + ['--foreground', - '--unmount-timeout=0.1', - self.mnt])): - return func(self, *args, **kwargs) + # Workaround for llfuse deadlock bug. See #10805, #8345, + # https://bitbucket.org/nikratio/python-llfuse/issues/108 + llfuse.close = lambda *args: None + + self.mount = None + try: + with arvados_fuse.command.Mount( + arvados_fuse.command.ArgumentParser().parse_args( + argv + ['--foreground', + '--unmount-timeout=2', + 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) return wrapper return decorator