summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2022-05-20 14:41:52 +0200
committerBenjamin Berg <bberg@redhat.com>2022-05-20 14:41:52 +0200
commit66eb9b9d7a56b5956e4b9df1bbd391226fd1bccf (patch)
tree33cf50d2f9a6bbe47056e91335c1f3901c02d2f8
parent41bceac6ef6acc43fe24ea3df8809eedbb93c369 (diff)
test: Stop processes using cleanup functionHEADmaster
Using tearDown is brittle, as an assertion will stop it from running through completely. So move cleanup into a helper that is called via addCleanup for logind and bluez.
-rwxr-xr-xsrc/linux/integration-test.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/linux/integration-test.py b/src/linux/integration-test.py
index 6cffb30..23fc972 100755
--- a/src/linux/integration-test.py
+++ b/src/linux/integration-test.py
@@ -152,21 +152,20 @@ class Tests(dbusmock.DBusTestCase):
self.daemon = None
self.start_logind({'CanHybridSleep' : 'yes'})
+ @classmethod
+ def stop_process(cls, proc, timeout=1):
+ proc.terminate()
+ try:
+ proc.wait(timeout)
+ except:
+ print("Killing %d (%s) after timeout of %f seconds" % (proc.pid, proc.args[0], timeout))
+ proc.kill()
+ proc.wait()
+
def tearDown(self):
del self.testbed
self.stop_daemon()
- if self.logind:
- self.logind.terminate()
- self.logind.wait()
-
- try:
- if self.bluez:
- self.bluez.terminate()
- self.bluez.wait()
- except:
- pass
-
#
# Daemon control and D-BUS I/O
#
@@ -294,10 +293,12 @@ class Tests(dbusmock.DBusTestCase):
def start_logind(self, parameters=None):
self.logind, self.logind_obj = self.spawn_server_template('logind',
parameters or {})
+ self.addCleanup(self.stop_process, self.logind)
def start_bluez(self, parameters=None):
self.bluez, self.bluez_obj = self.spawn_server_template('bluez5',
parameters or {})
+ self.addCleanup(self.stop_process, self.bluez)
def assertEventually(self, condition, message=None, timeout=50, value=True):
'''Assert that condition function eventually returns True.