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