From 89b4c4ee758e05b6e9236b0288e90f8bc48aae06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 25 Jan 2021 15:14:30 +0100 Subject: [PATCH] virtual-device: Test unplug operation while we're verifying --- tests/virtual-device.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/virtual-device.py b/tests/virtual-device.py index bf48c57..919c724 100644 --- a/tests/virtual-device.py +++ b/tests/virtual-device.py @@ -406,6 +406,39 @@ class VirtualDevice(unittest.TestCase): with self.assertRaisesRegex(GLib.GError, 'device has been removed from the system'): self.dev.close_sync() + def test_device_unplug_during_verify(self): + self._close_on_teardown = False + + notified_spec = None + def on_removed_notify(dev, spec): + nonlocal notified_spec + notified_spec = spec + + removed = False + def on_removed(dev): + nonlocal removed + removed = True + + self.assertFalse(self.dev.props.removed) + self.dev.connect('notify::removed', on_removed_notify) + self.dev.connect('removed', on_removed) + + self.start_verify(FPrint.Print.new(self.dev), + identify=self.dev.supports_identify()) + + self.send_command('UNPLUG') + self.assertEqual(notified_spec.name, 'removed') + self.assertTrue(self.dev.props.removed) + self.assertFalse(removed) + + with self.assertRaisesRegex(GLib.GError, 'device has been removed from the system'): + self.complete_verify() + + self.assertTrue(removed) + + with self.assertRaisesRegex(GLib.GError, 'device has been removed from the system'): + self.dev.close_sync() + class VirtualDeviceStorage(VirtualDevice): def tearDown(self):