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.
This commit is contained in:
Marek Marczykowski-Górecki 2017-10-20 02:41:14 +02:00
parent ae473a8c26
commit 43c09467b1
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 14 additions and 2 deletions

View File

@ -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()

View File

@ -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")