1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 from __future__ import absolute_import
8 import arvados_fuse.command
13 import multiprocessing
15 from . import run_test_server
29 def wrap_static_test_method(modName, clsName, funcName, args, kwargs):
30 class Test(unittest.TestCase):
31 def runTest(self, *args, **kwargs):
32 getattr(getattr(sys.modules[modName], clsName), funcName)(self, *args, **kwargs)
33 Test().runTest(*args, **kwargs)
36 # To avoid Python's threading+multiprocessing=deadlock problems, we
37 # use a single global pool with maxtasksperchild=None for the entire
43 _pool = multiprocessing.Pool(processes=1, maxtasksperchild=None)
47 class IntegrationTest(unittest.TestCase):
48 def pool_test(self, *args, **kwargs):
49 """Run a static method as a unit test, in a different process.
51 If called by method 'foobar', the static method '_foobar' of
52 the same class will be called in the other process.
54 modName = inspect.getmodule(self).__name__
55 clsName = self.__class__.__name__
56 funcName = inspect.currentframe().f_back.f_code.co_name
58 wrap_static_test_method,
59 (modName, clsName, '_'+funcName, args, kwargs))
64 run_test_server.run_keep(blob_signing=True, num_servers=2)
67 def tearDownClass(cls):
68 run_test_server.stop_keep(num_servers=2)
71 self.mnt = tempfile.mkdtemp()
72 run_test_server.authorize_with('active')
76 run_test_server.reset()
80 """Decorator. Sets up a FUSE mount at self.mnt with the given args."""
82 @functools.wraps(func)
83 def wrapper(self, *args, **kwargs):
86 with arvados_fuse.command.Mount(
87 arvados_fuse.command.ArgumentParser().parse_args(
88 argv + ['--foreground',
89 '--unmount-timeout=2',
90 self.mnt])) as self.mount:
91 return func(self, *args, **kwargs)
93 if self.mount and self.mount.llfuse_thread.is_alive():
94 logging.warning("IntegrationTest.mount:"
95 " llfuse thread still alive after umount"
96 " -- killing test suite to avoid deadlock")
97 os.kill(os.getpid(), signal.SIGKILL)