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