You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ju...@apache.org on 2022/01/13 17:20:17 UTC
[buildstream] 02/02: tests/testutils/artifactshare.py: Fix shutdown of test server
This is an automated email from the ASF dual-hosted git repository.
juergbi pushed a commit to branch juerg/tests-casd-server-shutdown
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 81621f6ade835499fa77f23116b5e647455f422e
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Thu Jan 13 17:42:12 2022 +0100
tests/testutils/artifactshare.py: Fix shutdown of test server
buildbox-casd processes used by test servers were not terminated and
kept running after the end of the tests (or crashed because the test
deleted the directories used by buildbox-casd).
---
tests/testutils/artifactshare.py | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py
index 8ce8a41..3a7a953 100644
--- a/tests/testutils/artifactshare.py
+++ b/tests/testutils/artifactshare.py
@@ -1,7 +1,6 @@
import os
import shutil
import signal
-import sys
from collections import namedtuple
from contextlib import ExitStack, contextmanager
from concurrent import futures
@@ -42,20 +41,11 @@ class BaseArtifactShare:
# Run the artifact server.
#
def run(self, q):
+ # Block SIGTERM and SIGINT to allow graceful shutdown and cleanup after initialization
+ signal.pthread_sigmask(signal.SIG_BLOCK, [signal.SIGTERM, signal.SIGINT])
+
with ExitStack() as stack:
try:
- # 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:
- from pytest_cov.embed import cleanup_on_sigterm
- except ImportError:
- pass
- else:
- cleanup_on_sigterm()
-
server = stack.enter_context(self._create_server())
port = server.add_insecure_port("localhost:0")
server.start()
@@ -67,7 +57,17 @@ class BaseArtifactShare:
q.put(port)
# Sleep until termination by signal
- signal.pause()
+ signal.sigwait([signal.SIGTERM, signal.SIGINT])
+
+ server.stop(0)
+
+ # Save collected coverage data
+ try:
+ from pytest_cov.embed import cleanup
+ except ImportError:
+ pass
+ else:
+ cleanup()
# _create_server()
#
@@ -83,6 +83,7 @@ class BaseArtifactShare:
def close(self):
self.process.terminate()
self.process.join()
+ assert self.process.exitcode == 0
# DummyArtifactShare()