summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-09-16 21:01:16 +0200
committerJürg Billeter <j@bitron.ch>2019-09-16 21:16:23 +0200
commit6ad1761d2f1798db21497265ae2efaae8bdcb844 (patch)
tree62526daf82e0572062d17453c6415dc51ff5a868
parent8418b56746412b988a069354296f7294be7ff304 (diff)
downloadbuildstream-6ad1761d2f1798db21497265ae2efaae8bdcb844.tar.gz
tests/testutils/artifactshare.py: Add SIGTERM handler to subprocessjuerg/artifactshare
pytest-cov 2.7 calls os._exit() in its SIGTERM handler, skipping cleanup, unless another SIGTERM handler was already registered. Add our own SIGTERM handler to the subprocess to ensure proper cleanup such as terminating buildbox-casd.
-rw-r--r--tests/testutils/artifactshare.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py
index f883b3d59..87b0808fe 100644
--- a/tests/testutils/artifactshare.py
+++ b/tests/testutils/artifactshare.py
@@ -1,6 +1,7 @@
import os
import shutil
import signal
+import sys
from collections import namedtuple
from contextlib import contextmanager
@@ -63,6 +64,11 @@ class ArtifactShare():
#
def run(self, q):
+ # Handle SIGTERM by calling sys.exit(0), which will raise a SystemExit exception,
+ # properly executing cleanup code in `finally` clauses and context managers.
+ # This is required to terminate buildbox-casd on SIGTERM.
+ signal.signal(signal.SIGTERM, lambda signalnum, frame: sys.exit(0))
+
try:
import pytest_cov
except ImportError: