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