From 43c09467b17fd1d9ee5fe903928ca3fe9e35123d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 20 Oct 2017 02:41:14 +0200 Subject: [PATCH] tests: cleanup QubesDB connection on domain remove If domain got removed during the tests (for example DispVM), vm.close() wouldn't be called in cleanup and some file descriptors will be leaked. Add event handler for cleaning this up. Do not use close() method here, because it is destructive, but the object may still be used by the test. --- qubes/tests/__init__.py | 10 ++++++++++ qubes/tests/integ/dispvm.py | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index 7363c88d..a2974df9 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -656,6 +656,16 @@ class SystemTestCase(QubesTestCase): self.addCleanup(self.cleanup_app) + self.app.add_handler('domain-delete', self.close_qdb_on_remove) + + def close_qdb_on_remove(self, app, event, vm, **kwargs): + # only close QubesDB connection, do not perform other (destructive) + # actions of vm.close() + if vm._qdb_connection_watch is not None: + asyncio.get_event_loop().remove_reader( + vm._qdb_connection_watch.watch_fd()) + vm._qdb_connection_watch.close() + vm._qdb_connection_watch = None def cleanup_app(self): self.remove_test_vms() diff --git a/qubes/tests/integ/dispvm.py b/qubes/tests/integ/dispvm.py index 33a77e0b..67d8ed3e 100644 --- a/qubes/tests/integ/dispvm.py +++ b/qubes/tests/integ/dispvm.py @@ -53,7 +53,6 @@ class TC_04_DispVM(qubes.tests.SystemTestCase): self.app.default_dispvm = None super(TC_04_DispVM, self).tearDown() - @unittest.expectedFailure def test_002_cleanup(self): self.loop.run_until_complete(self.testvm.start()) @@ -71,7 +70,6 @@ class TC_04_DispVM(qubes.tests.SystemTestCase): self.loop.run_until_complete(asyncio.sleep(1)) self.assertNotIn(dispvm_name, self.app.domains) - @unittest.expectedFailure def test_003_cleanup_destroyed(self): """ Check if DispVM is properly removed even if it terminated itself (#1660) @@ -160,11 +158,15 @@ class TC_20_DispVMMixin(object): self.wait_for_window(window_title, show=False) finally: p.stdin.close() + del p finally: self.loop.run_until_complete(dispvm.cleanup()) dispvm_name = dispvm.name del dispvm + # give it a time for shutdown + cleanup + self.loop.run_until_complete(asyncio.sleep(2)) + self.assertNotIn(dispvm_name, self.app.domains, "DispVM not removed from qubes.xml")