Skip to content

Commit

Permalink
tests: domain-shutdown event race condition
Browse files Browse the repository at this point in the history
Second tests, for actual events, not storage handling done by its
handler.

cc @HW42

QubesOS/qubes-issues#3164
  • Loading branch information
marmarek committed Oct 20, 2017
1 parent 54d6fb5 commit a21cf40
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions qubes/tests/integ/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,68 @@ def test_200_shutdown_event_race(self):
# one after another, private volume is gone
self.loop.run_until_complete(self.vm.storage.verify())

def _test_201_on_domain_pre_start(self, vm, event, **_kwargs):
'''Simulate domain crash just after startup'''
if not self.domain_shutdown_handled and not self.test_failure_reason:
self.test_failure_reason = \
'domain-shutdown event was not dispatched before subsequent ' \
'start'
self.domain_shutdown_handled = False

def _test_201_domain_shutdown_handler(self, vm, event, **kwargs):
if self.domain_shutdown_handled and not self.test_failure_reason:
self.test_failure_reason = 'domain-shutdown event received twice'
self.domain_shutdown_handled = True

@unittest.expectedFailure
def test_201_shutdown_event_race(self):
'''Regression test for 3164 - pure events edition'''
vmname = self.make_vm_name('appvm')

self.vm = self.app.add_new_vm(qubes.vm.appvm.AppVM,
name=vmname, template=self.app.default_template,
label='red')
# help the luck a little - don't wait for qrexec to easier win the race
self.vm.features['qrexec'] = False
self.loop.run_until_complete(self.vm.create_on_disk())

# do not throw exception from inside event handler - test framework
# will not recover from it (various objects leaks)
self.test_failure_reason = None
self.domain_shutdown_handled = False
self.vm.add_handler('domain-shutdown',
self._test_201_domain_shutdown_handler)

self.loop.run_until_complete(self.vm.start())

if self.test_failure_reason:
self.fail(self.test_failure_reason)

self.vm.add_handler('domain-pre-start',
self._test_201_on_domain_pre_start)

# kill it the way it does not give a chance for domain-shutdown it
# execute
self.vm.libvirt_domain.destroy()

# now, lets try to start the VM again, before domain-shutdown event
# got handled (#3164), and immediately trigger second domain-shutdown
self.vm.add_handler('domain-start', self._test_200_on_domain_start)
self.loop.run_until_complete(self.vm.start())

if self.test_failure_reason:
self.fail(self.test_failure_reason)

# and give a chance for both domain-shutdown handlers to execute
self.loop.run_until_complete(asyncio.sleep(1))

if self.test_failure_reason:
self.fail(self.test_failure_reason)

self.assertTrue(self.domain_shutdown_handled,
'second domain-shutdown event was not dispatched after domain '
'shutdown')


class TC_01_Properties(qubes.tests.SystemTestCase):
# pylint: disable=attribute-defined-outside-init
Expand Down

0 comments on commit a21cf40

Please sign in to comment.