mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2025-12-26 20:10:04 +01:00
test: Stop processes using cleanup function
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.
This commit is contained in:
parent
41bceac6ef
commit
66eb9b9d7a
1 changed files with 12 additions and 11 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue