diff options
author | Jim MacArthur <jim+gitlab@mode7.co.uk> | 2018-11-27 10:31:07 +0000 |
---|---|---|
committer | Jim MacArthur <jim+gitlab@mode7.co.uk> | 2018-11-27 10:31:07 +0000 |
commit | d09a18b8522a528f7035302f97b3692fd5c8cddc (patch) | |
tree | dc92c08ef1282ffed4af2e83349044bec9d4e04e | |
parent | 5af455a48a70a7ad910da29569276dd796c8b698 (diff) | |
parent | 4ca892e3d99b8cc112460c87ce82344995021058 (diff) | |
download | buildstream-d09a18b8522a528f7035302f97b3692fd5c8cddc.tar.gz |
Merge branch 'jmac/fix-test-hangs-2' into 'master'
Avoid hanging artifact cache tests
See merge request BuildStream/buildstream!964
-rw-r--r-- | tests/artifactcache/pull.py | 29 | ||||
-rw-r--r-- | tests/artifactcache/push.py | 28 | ||||
-rw-r--r-- | tests/testutils/artifactshare.py | 25 |
3 files changed, 55 insertions, 27 deletions
diff --git a/tests/artifactcache/pull.py b/tests/artifactcache/pull.py index dde451a8c..4c332bf36 100644 --- a/tests/artifactcache/pull.py +++ b/tests/artifactcache/pull.py @@ -25,6 +25,17 @@ def message_handler(message, context): pass +# Since parent processes wait for queue events, we need +# to put something on it if the called process raises an +# exception. +def _queue_wrapper(target, queue, *args): + try: + target(*args, queue=queue) + except Exception as e: + queue.put(str(e)) + raise + + def tree_maker(cas, tree, directory): if tree.root.ByteSize() == 0: tree.root.CopyFrom(directory) @@ -97,9 +108,9 @@ def test_pull(cli, tmpdir, datafiles): queue = multiprocessing.Queue() # Use subprocess to avoid creation of gRPC threads in main BuildStream process # See https://github.com/grpc/grpc/blob/master/doc/fork_support.md for details - process = multiprocessing.Process(target=_test_pull, - args=(user_config_file, project_dir, artifact_dir, - 'target.bst', element_key, queue)) + process = multiprocessing.Process(target=_queue_wrapper, + args=(_test_pull, queue, user_config_file, project_dir, + artifact_dir, 'target.bst', element_key)) try: # Keep SIGINT blocked in the child process @@ -205,9 +216,9 @@ def test_pull_tree(cli, tmpdir, datafiles): queue = multiprocessing.Queue() # Use subprocess to avoid creation of gRPC threads in main BuildStream process # See https://github.com/grpc/grpc/blob/master/doc/fork_support.md for details - process = multiprocessing.Process(target=_test_push_tree, - args=(user_config_file, project_dir, artifact_dir, - artifact_digest, queue)) + process = multiprocessing.Process(target=_queue_wrapper, + args=(_test_push_tree, queue, user_config_file, project_dir, + artifact_dir, artifact_digest)) try: # Keep SIGINT blocked in the child process @@ -233,9 +244,9 @@ def test_pull_tree(cli, tmpdir, datafiles): queue = multiprocessing.Queue() # Use subprocess to avoid creation of gRPC threads in main BuildStream process - process = multiprocessing.Process(target=_test_pull_tree, - args=(user_config_file, project_dir, artifact_dir, - tree_digest, queue)) + process = multiprocessing.Process(target=_queue_wrapper, + args=(_test_pull_tree, queue, user_config_file, project_dir, + artifact_dir, tree_digest)) try: # Keep SIGINT blocked in the child process diff --git a/tests/artifactcache/push.py b/tests/artifactcache/push.py index 746884e29..116fa7865 100644 --- a/tests/artifactcache/push.py +++ b/tests/artifactcache/push.py @@ -26,6 +26,17 @@ def message_handler(message, context): pass +# Since parent processes wait for queue events, we need +# to put something on it if the called process raises an +# exception. +def _queue_wrapper(target, queue, *args): + try: + target(*args, queue=queue) + except Exception as e: + queue.put(str(e)) + raise + + @pytest.mark.datafiles(DATA_DIR) def test_push(cli, tmpdir, datafiles): project_dir = str(datafiles) @@ -76,9 +87,9 @@ def test_push(cli, tmpdir, datafiles): queue = multiprocessing.Queue() # Use subprocess to avoid creation of gRPC threads in main BuildStream process # See https://github.com/grpc/grpc/blob/master/doc/fork_support.md for details - process = multiprocessing.Process(target=_test_push, - args=(user_config_file, project_dir, artifact_dir, - 'target.bst', element_key, queue)) + process = multiprocessing.Process(target=_queue_wrapper, + args=(_test_push, queue, user_config_file, project_dir, + artifact_dir, 'target.bst', element_key)) try: # Keep SIGINT blocked in the child process @@ -185,9 +196,9 @@ def test_push_directory(cli, tmpdir, datafiles): queue = multiprocessing.Queue() # Use subprocess to avoid creation of gRPC threads in main BuildStream process # See https://github.com/grpc/grpc/blob/master/doc/fork_support.md for details - process = multiprocessing.Process(target=_test_push_directory, - args=(user_config_file, project_dir, artifact_dir, - artifact_digest, queue)) + process = multiprocessing.Process(target=_queue_wrapper, + args=(_test_push_directory, queue, user_config_file, + project_dir, artifact_dir, artifact_digest)) try: # Keep SIGINT blocked in the child process @@ -260,8 +271,9 @@ def test_push_message(cli, tmpdir, datafiles): queue = multiprocessing.Queue() # Use subprocess to avoid creation of gRPC threads in main BuildStream process # See https://github.com/grpc/grpc/blob/master/doc/fork_support.md for details - process = multiprocessing.Process(target=_test_push_message, - args=(user_config_file, project_dir, artifact_dir, queue)) + process = multiprocessing.Process(target=_queue_wrapper, + args=(_test_push_message, queue, user_config_file, + project_dir, artifact_dir)) try: # Keep SIGINT blocked in the child process diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py index 5194e83cf..31b96be73 100644 --- a/tests/testutils/artifactshare.py +++ b/tests/testutils/artifactshare.py @@ -67,19 +67,24 @@ class ArtifactShare(): def run(self, q): pytest_cov.embed.cleanup_on_sigterm() - # Optionally mock statvfs - if self.total_space: - if self.free_space is None: - self.free_space = self.total_space - os.statvfs = self._mock_statvfs + try: + # Optionally mock statvfs + if self.total_space: + if self.free_space is None: + self.free_space = self.total_space + os.statvfs = self._mock_statvfs + + server = create_server(self.repodir, enable_push=True) + port = server.add_insecure_port('localhost:0') - server = create_server(self.repodir, enable_push=True) - port = server.add_insecure_port('localhost:0') + server.start() - server.start() + # Send port to parent + q.put(port) - # Send port to parent - q.put(port) + except Exception as e: + q.put(None) + raise # Sleep until termination by signal signal.pause() |