summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-07-12 05:40:20 +0200
committerJürg Billeter <j@bitron.ch>2019-08-20 07:41:23 +0200
commitf59a86ed50f71ab6326e3e65f79e6bbd19ea5eae (patch)
treefc4dcb89868f24635987a090043e98f361b51c63 /tests
parent704266c2091eb3302fc979a892142a852564a55c (diff)
downloadbuildstream-f59a86ed50f71ab6326e3e65f79e6bbd19ea5eae.tar.gz
tests/internals/storage.py: Run tests in subprocess
This is in preparation for buildbox-casd, which will disallow local CAS cache writes from the main process (gRPC).
Diffstat (limited to 'tests')
-rw-r--r--tests/internals/storage.py60
1 files changed, 55 insertions, 5 deletions
diff --git a/tests/internals/storage.py b/tests/internals/storage.py
index 66423afd1..c23283221 100644
--- a/tests/internals/storage.py
+++ b/tests/internals/storage.py
@@ -1,7 +1,10 @@
+import multiprocessing
import os
+import signal
import pytest
+from buildstream import utils, _signals
from buildstream._cas import CASCache
from buildstream.storage._casbaseddirectory import CasBasedDirectory
from buildstream.storage._filebaseddirectory import FileBasedDirectory
@@ -12,6 +15,19 @@ DATA_DIR = os.path.join(
)
+# 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)
+ except Exception as e:
+ queue.put(str(e))
+ raise
+
+ queue.put(None)
+
+
def setup_backend(backend_class, tmpdir):
if backend_class == FileBasedDirectory:
return backend_class(os.path.join(tmpdir, "vdir"))
@@ -20,10 +36,7 @@ def setup_backend(backend_class, tmpdir):
return backend_class(cas_cache)
-@pytest.mark.parametrize("backend", [
- FileBasedDirectory, CasBasedDirectory])
-@pytest.mark.datafiles(DATA_DIR)
-def test_import(tmpdir, datafiles, backend):
+def _test_import_subprocess(tmpdir, datafiles, backend):
original = os.path.join(str(datafiles), "original")
c = setup_backend(backend, str(tmpdir))
@@ -37,7 +50,24 @@ def test_import(tmpdir, datafiles, backend):
@pytest.mark.parametrize("backend", [
FileBasedDirectory, CasBasedDirectory])
@pytest.mark.datafiles(DATA_DIR)
-def test_modified_file_list(tmpdir, datafiles, backend):
+def test_import(tmpdir, datafiles, backend):
+ queue = multiprocessing.Queue()
+ process = multiprocessing.Process(target=_queue_wrapper,
+ args=(_test_import_subprocess, queue,
+ tmpdir, datafiles, backend))
+ try:
+ with _signals.blocked([signal.SIGINT], ignore=False):
+ process.start()
+ error = queue.get()
+ process.join()
+ except KeyboardInterrupt:
+ utils._kill_process_tree(process.pid)
+ raise
+
+ assert not error
+
+
+def _test_modified_file_list_subprocess(tmpdir, datafiles, backend):
original = os.path.join(str(datafiles), "original")
overlay = os.path.join(str(datafiles), "overlay")
@@ -53,3 +83,23 @@ def test_modified_file_list(tmpdir, datafiles, backend):
assert "bin/bash" in c.list_relative_paths()
assert "bin/bash" in c.list_modified_paths()
assert "bin/hello" not in c.list_modified_paths()
+
+
+@pytest.mark.parametrize("backend", [
+ FileBasedDirectory, CasBasedDirectory])
+@pytest.mark.datafiles(DATA_DIR)
+def test_modified_file_list(tmpdir, datafiles, backend):
+ queue = multiprocessing.Queue()
+ process = multiprocessing.Process(target=_queue_wrapper,
+ args=(_test_modified_file_list_subprocess, queue,
+ tmpdir, datafiles, backend))
+ try:
+ with _signals.blocked([signal.SIGINT], ignore=False):
+ process.start()
+ error = queue.get()
+ process.join()
+ except KeyboardInterrupt:
+ utils._kill_process_tree(process.pid)
+ raise
+
+ assert not error