cb3b00
From e5b0e0948a422e5cc241efe0b55a1e841e2ca29c Mon Sep 17 00:00:00 2001
cb3b00
From: Benjamin Berg <bberg@redhat.com>
cb3b00
Date: Thu, 26 Aug 2021 14:26:40 +0200
cb3b00
Subject: [PATCH 1/3] tests: Set G_MESSAGES_DEBUG=all for daemon as it is
cb3b00
 needed
cb3b00
cb3b00
Otherwise executing the test script outside of the meson environment
cb3b00
will fail as the inhibitor test relies on being able to parse the log.
cb3b00
---
cb3b00
 tests/fprintd.py | 2 ++
cb3b00
 1 file changed, 2 insertions(+)
cb3b00
cb3b00
diff --git a/tests/fprintd.py b/tests/fprintd.py
cb3b00
index 8fa615f..801ee81 100644
cb3b00
--- a/tests/fprintd.py
cb3b00
+++ b/tests/fprintd.py
cb3b00
@@ -237,6 +237,8 @@ class FPrintdTest(dbusmock.DBusTestCase):
cb3b00
         env['G_DEBUG'] = 'fatal-criticals'
cb3b00
         env['STATE_DIRECTORY'] = (self.state_dir + ':' + '/hopefully/a/state_dir_path/that/shouldnt/be/writable')
cb3b00
         env['RUNTIME_DIRECTORY'] = self.run_dir
cb3b00
+        # The tests parses the debug output for suspend inhibitor debugging
cb3b00
+        env['G_MESSAGES_DEBUG'] = 'all'
cb3b00
 
cb3b00
         argv = [self.paths['daemon'], '-t']
cb3b00
         valgrind = os.getenv('VALGRIND')
cb3b00
-- 
cb3b00
GitLab
cb3b00
cb3b00
cb3b00
From 8ca81d5166b47300e99ba5637f4b3c7fa9a00cd4 Mon Sep 17 00:00:00 2001
cb3b00
From: Benjamin Berg <bberg@redhat.com>
cb3b00
Date: Thu, 26 Aug 2021 14:23:15 +0200
cb3b00
Subject: [PATCH 2/3] tests: Use dbusmock start_system_bus instead of GLib
cb3b00
 server
cb3b00
cb3b00
---
cb3b00
 tests/fprintd.py | 11 ++---------
cb3b00
 1 file changed, 2 insertions(+), 9 deletions(-)
cb3b00
cb3b00
diff --git a/tests/fprintd.py b/tests/fprintd.py
cb3b00
index 801ee81..6754a56 100644
cb3b00
--- a/tests/fprintd.py
cb3b00
+++ b/tests/fprintd.py
cb3b00
@@ -211,14 +211,8 @@ class FPrintdTest(dbusmock.DBusTestCase):
cb3b00
             n = os.path.basename(f)[:-4]
cb3b00
             cls.prints[n] = load_image(f)
cb3b00
 
cb3b00
-
cb3b00
-        cls.test_bus = Gio.TestDBus.new(Gio.TestDBusFlags.NONE)
cb3b00
-        cls.test_bus.up()
cb3b00
-        cls.addClassCleanup(cls.test_bus.down)
cb3b00
-        cls.test_bus.unset()
cb3b00
-        addr = cls.test_bus.get_bus_address()
cb3b00
-        os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = addr
cb3b00
-        cls.dbus = Gio.DBusConnection.new_for_address_sync(addr,
cb3b00
+        cls.start_system_bus()
cb3b00
+        cls.dbus = Gio.DBusConnection.new_for_address_sync(os.environ['DBUS_SYSTEM_BUS_ADDRESS'],
cb3b00
             Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION |
cb3b00
             Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT, None, None)
cb3b00
         assert cls.dbus.is_closed() == False
cb3b00
@@ -229,7 +223,6 @@ class FPrintdTest(dbusmock.DBusTestCase):
cb3b00
         dbusmock.DBusTestCase.tearDownClass()
cb3b00
 
cb3b00
         del cls.dbus
cb3b00
-        del cls.test_bus
cb3b00
 
cb3b00
     def daemon_start(self, driver='Virtual image device for debugging'):
cb3b00
         timeout = get_timeout('daemon_start')  # seconds
cb3b00
-- 
cb3b00
GitLab
cb3b00
cb3b00
cb3b00
From 84ad711d48952e129abfad3bd2f509d30af65eb6 Mon Sep 17 00:00:00 2001
cb3b00
From: Benjamin Berg <bberg@redhat.com>
cb3b00
Date: Thu, 26 Aug 2021 14:25:12 +0200
cb3b00
Subject: [PATCH 3/3] tests: Better cleanup helper processes and objects
cb3b00
cb3b00
We were leaking the bus connections for the proxy objects. Also, now the
cb3b00
subprocesses will be forcefully killed at shutdown.
cb3b00
---
cb3b00
 tests/fprintd.py | 20 +++++++++++++++-----
cb3b00
 1 file changed, 15 insertions(+), 5 deletions(-)
cb3b00
cb3b00
diff --git a/tests/fprintd.py b/tests/fprintd.py
cb3b00
index 6754a56..f828b27 100644
cb3b00
--- a/tests/fprintd.py
cb3b00
+++ b/tests/fprintd.py
cb3b00
@@ -243,6 +243,7 @@ class FPrintdTest(dbusmock.DBusTestCase):
cb3b00
             self.valgrind = True
cb3b00
         self.kill_daemon = False
cb3b00
         self.daemon_log = OutputChecker()
cb3b00
+        self.addCleanup(self.daemon_log.force_close)
cb3b00
         self.daemon = subprocess.Popen(argv,
cb3b00
                                        env=env,
cb3b00
                                        stdout=self.daemon_log.fd,
cb3b00
@@ -330,14 +331,23 @@ class FPrintdTest(dbusmock.DBusTestCase):
cb3b00
 
cb3b00
         self._polkitd, self._polkitd_obj = self.spawn_server_template(
cb3b00
             polkitd_template, {}, stdout=subprocess.PIPE)
cb3b00
+        self.addCleanup(self.stop_server, '_polkitd', '_polkitd_obj')
cb3b00
 
cb3b00
         return self._polkitd
cb3b00
 
cb3b00
-    def polkitd_stop(self):
cb3b00
-        if self._polkitd is None:
cb3b00
+    def stop_server(self, proc_attr, obj_attr):
cb3b00
+        proc = getattr(self, proc_attr, None)
cb3b00
+        if proc is None:
cb3b00
             return
cb3b00
-        self._polkitd.terminate()
cb3b00
-        self._polkitd.wait()
cb3b00
+
cb3b00
+        proc.terminate()
cb3b00
+        try:
cb3b00
+            proc.wait(timeout=1)
cb3b00
+        except subprocess.TimeoutExpired as e:
cb3b00
+            proc.kill()
cb3b00
+
cb3b00
+        delattr(self, proc_attr)
cb3b00
+        delattr(self, obj_attr)
cb3b00
 
cb3b00
     def polkitd_allow_all(self):
cb3b00
         self._polkitd_obj.SetAllowed([FprintDevicePermission.set_username,
cb3b00
@@ -593,7 +603,6 @@ class FPrintdVirtualDeviceBaseTest(FPrintdVirtualImageDeviceBaseTests):
cb3b00
         self.manager = None
cb3b00
         self.device = None
cb3b00
         self.polkitd_start()
cb3b00
-        self.addCleanup(self.polkitd_stop)
cb3b00
 
cb3b00
         fifo_path = os.path.join(self.tmpdir, 'logind_inhibit_fifo')
cb3b00
         os.mkfifo(fifo_path)
cb3b00
@@ -608,6 +617,7 @@ class FPrintdVirtualDeviceBaseTest(FPrintdVirtualImageDeviceBaseTests):
cb3b00
                                   'ret = os.open("%s", os.O_WRONLY)\n' % fifo_path +
cb3b00
                                   'from gi.repository import GLib\n' +
cb3b00
                                   'GLib.idle_add(lambda fd: os.close(fd), ret)')
cb3b00
+        self.addCleanup(self.stop_server, 'logind', 'logind_obj')
cb3b00
         self.daemon_start(self.driver_name)
cb3b00
 
cb3b00
         self.wait_got_delay_inhibitor(timeout=5)
cb3b00
-- 
cb3b00
GitLab
cb3b00