Browse Source

tests: teardown fixes

Add few missing app.close() calls on test teardown.
Fix socket cleanup in TC_00_QubesDaemonProtocol() - not only close the
FD, but also unregister it from asyncio event loop.
Marek Marczykowski-Górecki 4 years ago
parent
commit
0341cc5258
3 changed files with 14 additions and 2 deletions
  1. 6 2
      qubes/tests/api.py
  2. 6 0
      qubes/tests/app.py
  3. 2 0
      qubes/tests/storage_lvm.py

+ 6 - 2
qubes/tests/api.py

@@ -109,8 +109,12 @@ class TC_00_QubesDaemonProtocol(qubes.tests.QubesTestCase):
             connect_coro)
 
     def tearDown(self):
-        self.sock_server.close()
-        self.sock_client.close()
+        self.writer.close()
+        try:
+            self.loop.run_until_complete(self.writer.wait_closed())
+        except AttributeError:  # old python in travis
+            pass
+        self.transport.close()
         super(TC_00_QubesDaemonProtocol, self).tearDown()
 
     def test_000_message_ok(self):

+ 6 - 0
qubes/tests/app.py

@@ -480,6 +480,9 @@ class TC_89_QubesEmpty(qubes.tests.QubesTestCase):
             with self.assertRaises(AttributeError):
                 self.app.default_fw_netvm
 
+            self.app.close()
+            del self.app
+
         with self.subTest('loop'):
             with open('/tmp/qubestest.xml', 'w') as xml_file:
                 xml_file.write(xml_template.format(
@@ -502,6 +505,9 @@ class TC_89_QubesEmpty(qubes.tests.QubesTestCase):
             with self.assertRaises(AttributeError):
                 self.app.default_fw_netvm
 
+            self.app.close()
+            del self.app
+
 
 class TC_90_Qubes(qubes.tests.QubesTestCase):
     def tearDown(self):

+ 2 - 0
qubes/tests/storage_lvm.py

@@ -131,6 +131,7 @@ class TC_00_ThinPool(ThinPoolBase):
     def tearDown(self):
         super(TC_00_ThinPool, self).tearDown()
         os.unlink(self.app.store)
+        self.app.close()
         del self.app
         for attr in dir(self):
             if isinstance(getattr(self, attr), qubes.vm.BaseVM):
@@ -1141,6 +1142,7 @@ class TC_02_StorageHelpers(ThinPoolBase):
         self.thin_dir.cleanup()
         super(TC_02_StorageHelpers, self).tearDown()
         os.unlink(self.app.store)
+        self.app.close()
         del self.app
         for attr in dir(self):
             if isinstance(getattr(self, attr), qubes.vm.BaseVM):