tests/virtual-device: Check that removed devices are not in context anymore

This commit is contained in:
Marco Trevisan (Treviño)
2023-06-22 00:34:05 -04:00
parent c27d72e3a1
commit 4d96a3efaa

View File

@@ -362,13 +362,22 @@ class VirtualDeviceUnplugging(VirtualDeviceBase):
notified_spec = spec
removed = False
ctx_removed = False
def on_ctx_removed(ctx, dev):
nonlocal ctx_removed
ctx_removed = dev == self.dev
self.assertEqual(removed, ctx_removed)
def on_removed(dev):
nonlocal removed
removed = dev.props.removed
self.assertNotEqual(removed, ctx_removed)
self.assertFalse(self.dev.props.removed)
self.dev.connect('notify::removed', on_removed_notify)
self.ctx.connect('device-removed', on_ctx_removed)
self.dev.connect('removed', on_removed)
self.send_command('UNPLUG')
self.assertEqual(notified_spec.name, 'removed')
@@ -381,6 +390,11 @@ class VirtualDeviceUnplugging(VirtualDeviceBase):
self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(),
FPrint.DeviceError.REMOVED))
while not ctx_removed:
ctx.iteration(True)
self.assertNotIn(self.dev, self.ctx.get_devices())
def test_device_unplug_during_verify(self):
self._close_on_teardown = False
self._destroy_on_teardown = True
@@ -391,12 +405,21 @@ class VirtualDeviceUnplugging(VirtualDeviceBase):
notified_spec = spec
removed = False
ctx_removed = False
def on_ctx_removed(ctx, dev):
nonlocal ctx_removed
ctx_removed = dev == self.dev
self.assertEqual(removed, ctx_removed)
def on_removed(dev):
nonlocal removed
removed = dev.props.removed
self.assertNotEqual(removed, ctx_removed)
self.assertFalse(self.dev.props.removed)
self.dev.connect('notify::removed', on_removed_notify)
self.ctx.connect('device-removed', on_ctx_removed)
self.dev.connect('removed', on_removed)
self.start_verify(FPrint.Print.new(self.dev),
@@ -421,6 +444,11 @@ class VirtualDeviceUnplugging(VirtualDeviceBase):
self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(),
FPrint.DeviceError.REMOVED))
while not ctx_removed:
ctx.iteration(True)
self.assertNotIn(self.dev, self.ctx.get_devices())
class VirtualDevice(VirtualDeviceBase):