From caa4cce0bc97ae99bc1657c3126d3c098e959eaa Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Thu, 8 Sep 2016 09:34:31 -0400 Subject: [PATCH] 9986: Share one multiprocessing pool with all IntegrationTests. --- services/fuse/tests/integration_test.py | 30 +++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/services/fuse/tests/integration_test.py b/services/fuse/tests/integration_test.py index 5a45bfc103..d0e3102b67 100644 --- a/services/fuse/tests/integration_test.py +++ b/services/fuse/tests/integration_test.py @@ -1,14 +1,28 @@ import arvados import arvados_fuse import arvados_fuse.command +import atexit import functools import inspect 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 +38,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): -- 2.39.5