cb3b00
From 5d7422e17aaaf3a0c09fc4a3c8f6fa67371d3130 Mon Sep 17 00:00:00 2001
cb3b00
From: Benjamin Berg <bberg@redhat.com>
cb3b00
Date: Wed, 25 Aug 2021 13:43:30 +0200
cb3b00
Subject: [PATCH 1/4] tests: Cleanup inhibitor fifo properly
cb3b00
cb3b00
Unlink the fifo itself and use addCleanup to close it.
cb3b00
---
cb3b00
 tests/fprintd.py | 4 ++--
cb3b00
 1 file changed, 2 insertions(+), 2 deletions(-)
cb3b00
cb3b00
diff --git a/tests/fprintd.py b/tests/fprintd.py
cb3b00
index a274793..f0dbc7b 100644
cb3b00
--- a/tests/fprintd.py
cb3b00
+++ b/tests/fprintd.py
cb3b00
@@ -601,7 +601,9 @@ class FPrintdVirtualDeviceBaseTest(FPrintdVirtualImageDeviceBaseTests):
cb3b00
 
cb3b00
         fifo_path = os.path.join(self.tmpdir, 'logind_inhibit_fifo')
cb3b00
         os.mkfifo(fifo_path)
cb3b00
+        self.addCleanup(os.unlink, fifo_path)
cb3b00
         self.logind_inhibit_fifo = os.open(fifo_path, os.O_RDONLY | os.O_NONBLOCK | os.O_CLOEXEC)
cb3b00
+        self.addCleanup(os.close, self.logind_inhibit_fifo)
cb3b00
         # EOF without a writer, BlockingIOError with a writer
cb3b00
         self.assertFalse(self.holds_inhibitor())
cb3b00
 
cb3b00
@@ -662,8 +664,6 @@ class FPrintdVirtualDeviceBaseTest(FPrintdVirtualImageDeviceBaseTests):
cb3b00
         self.device = None
cb3b00
         self.manager = None
cb3b00
 
cb3b00
-        os.close(self.logind_inhibit_fifo)
cb3b00
-
cb3b00
         super().tearDown()
cb3b00
 
cb3b00
     def try_release(self):
cb3b00
-- 
cb3b00
GitLab
cb3b00
cb3b00
cb3b00
From e6fc854a9ae3f640945ff621959cf9984e7d036a Mon Sep 17 00:00:00 2001
cb3b00
From: Benjamin Berg <bberg@redhat.com>
cb3b00
Date: Wed, 25 Aug 2021 15:19:43 +0200
cb3b00
Subject: [PATCH 2/4] tests: Use addCleanup to stop polkitd
cb3b00
cb3b00
---
cb3b00
 tests/fprintd.py | 2 +-
cb3b00
 1 file changed, 1 insertion(+), 1 deletion(-)
cb3b00
cb3b00
diff --git a/tests/fprintd.py b/tests/fprintd.py
cb3b00
index f0dbc7b..0dea501 100644
cb3b00
--- a/tests/fprintd.py
cb3b00
+++ b/tests/fprintd.py
cb3b00
@@ -598,6 +598,7 @@ 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
@@ -660,7 +661,6 @@ class FPrintdVirtualDeviceBaseTest(FPrintdVirtualImageDeviceBaseTests):
cb3b00
         self._changed_properties = []
cb3b00
 
cb3b00
     def tearDown(self):
cb3b00
-        self.polkitd_stop()
cb3b00
         self.device = None
cb3b00
         self.manager = None
cb3b00
 
cb3b00
-- 
cb3b00
GitLab
cb3b00
cb3b00
cb3b00
From 717a9199963d1ea8c96f9208ecdca18a12247481 Mon Sep 17 00:00:00 2001
cb3b00
From: Benjamin Berg <bberg@redhat.com>
cb3b00
Date: Wed, 25 Aug 2021 15:22:42 +0200
cb3b00
Subject: [PATCH 3/4] tests: Make class cleanup more robust
cb3b00
cb3b00
Use addClassCleanup rather than doing cleanup in tearDownClass, which
cb3b00
may not be called in all cases.
cb3b00
---
cb3b00
 tests/fprintd.py | 10 +++++-----
cb3b00
 1 file changed, 5 insertions(+), 5 deletions(-)
cb3b00
cb3b00
diff --git a/tests/fprintd.py b/tests/fprintd.py
cb3b00
index 0dea501..7d9eb4d 100644
cb3b00
--- a/tests/fprintd.py
cb3b00
+++ b/tests/fprintd.py
cb3b00
@@ -201,6 +201,7 @@ class FPrintdTest(dbusmock.DBusTestCase):
cb3b00
 
cb3b00
 
cb3b00
         cls.tmpdir = tempfile.mkdtemp(prefix='libfprint-')
cb3b00
+        cls.addClassCleanup(shutil.rmtree, cls.tmpdir)
cb3b00
 
cb3b00
         cls.sockaddr = os.path.join(cls.tmpdir, 'virtual-image.socket')
cb3b00
         os.environ[cls.socket_env] = cls.sockaddr
cb3b00
@@ -213,6 +214,7 @@ class FPrintdTest(dbusmock.DBusTestCase):
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
@@ -220,16 +222,14 @@ class FPrintdTest(dbusmock.DBusTestCase):
cb3b00
             Gio.DBusConnectionFlags.MESSAGE_BUS_CONNECTION |
cb3b00
             Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT, None, None)
cb3b00
         assert cls.dbus.is_closed() == False
cb3b00
+        cls.addClassCleanup(cls.dbus.close)
cb3b00
 
cb3b00
     @classmethod
cb3b00
     def tearDownClass(cls):
cb3b00
-        cls.dbus.close()
cb3b00
-        cls.test_bus.down()
cb3b00
-        del cls.dbus
cb3b00
-        del cls.test_bus
cb3b00
-        shutil.rmtree(cls.tmpdir)
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 e4c155d5b8ea48e337e64c24170be023229bbb07 Mon Sep 17 00:00:00 2001
cb3b00
From: Benjamin Berg <bberg@redhat.com>
cb3b00
Date: Wed, 25 Aug 2021 15:27:26 +0200
cb3b00
Subject: [PATCH 4/4] tests: Give fprintd some more time to be ready
cb3b00
cb3b00
While the delay inhibitor is grabbed almost immediately, this can be
cb3b00
slow enough to not have happened immediately after the bus name has been
cb3b00
registered. Add a generous timeout to prevent issues.
cb3b00
---
cb3b00
 tests/fprintd.py | 2 +-
cb3b00
 1 file changed, 1 insertion(+), 1 deletion(-)
cb3b00
cb3b00
diff --git a/tests/fprintd.py b/tests/fprintd.py
cb3b00
index 7d9eb4d..8fa615f 100644
cb3b00
--- a/tests/fprintd.py
cb3b00
+++ b/tests/fprintd.py
cb3b00
@@ -615,7 +615,7 @@ class FPrintdVirtualDeviceBaseTest(FPrintdVirtualImageDeviceBaseTests):
cb3b00
                                   'GLib.idle_add(lambda fd: os.close(fd), ret)')
cb3b00
         self.daemon_start(self.driver_name)
cb3b00
 
cb3b00
-        self.wait_got_delay_inhibitor()
cb3b00
+        self.wait_got_delay_inhibitor(timeout=5)
cb3b00
 
cb3b00
         if self.device is None:
cb3b00
             self.skipTest("Need {} device to run the test".format(self.device_driver))
cb3b00
-- 
cb3b00
GitLab
cb3b00