tests/virtual-device: Add a class function to wait for a timeout
This commit is contained in:
parent
2382506491
commit
3db0858fb0
1 changed files with 14 additions and 26 deletions
|
@ -94,6 +94,16 @@ class VirtualDevice(unittest.TestCase):
|
||||||
self.assertFalse(self.dev.is_open())
|
self.assertFalse(self.dev.is_open())
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
|
def wait_timeout(self, interval):
|
||||||
|
timeout_reached = False
|
||||||
|
def on_timeout():
|
||||||
|
nonlocal timeout_reached
|
||||||
|
timeout_reached = True
|
||||||
|
|
||||||
|
GLib.timeout_add(interval, on_timeout)
|
||||||
|
while not timeout_reached:
|
||||||
|
ctx.iteration(False)
|
||||||
|
|
||||||
def send_command(self, command, *args):
|
def send_command(self, command, *args):
|
||||||
self.assertIn(command, ['INSERT', 'REMOVE', 'SCAN', 'ERROR', 'RETRY',
|
self.assertIn(command, ['INSERT', 'REMOVE', 'SCAN', 'ERROR', 'RETRY',
|
||||||
'FINGER', 'UNPLUG', 'SLEEP', 'SET_ENROLL_STAGES', 'SET_SCAN_TYPE',
|
'FINGER', 'UNPLUG', 'SLEEP', 'SET_ENROLL_STAGES', 'SET_SCAN_TYPE',
|
||||||
|
@ -458,55 +468,33 @@ class VirtualDevice(unittest.TestCase):
|
||||||
self.dev.close_sync()
|
self.dev.close_sync()
|
||||||
|
|
||||||
def test_device_sleep(self):
|
def test_device_sleep(self):
|
||||||
timeout_reached = False
|
|
||||||
def on_timeout():
|
|
||||||
nonlocal timeout_reached
|
|
||||||
timeout_reached = True
|
|
||||||
|
|
||||||
self.send_command('SLEEP', 1500)
|
self.send_command('SLEEP', 1500)
|
||||||
GLib.timeout_add(300, on_timeout)
|
|
||||||
|
|
||||||
self.start_verify(FPrint.Print.new(self.dev),
|
self.start_verify(FPrint.Print.new(self.dev),
|
||||||
identify=self.dev.supports_identify())
|
identify=self.dev.supports_identify())
|
||||||
while not timeout_reached:
|
|
||||||
ctx.iteration(False)
|
|
||||||
|
|
||||||
|
self.wait_timeout(300)
|
||||||
self.assertFalse(self._verify_completed)
|
self.assertFalse(self._verify_completed)
|
||||||
|
|
||||||
timeout_reached = False
|
|
||||||
self._cancellable.cancel()
|
self._cancellable.cancel()
|
||||||
GLib.timeout_add(200, on_timeout)
|
self.wait_timeout(200)
|
||||||
|
|
||||||
while not timeout_reached:
|
|
||||||
ctx.iteration(False)
|
|
||||||
|
|
||||||
self.assertTrue(self._verify_completed)
|
self.assertTrue(self._verify_completed)
|
||||||
self.cancel_verify()
|
self.cancel_verify()
|
||||||
|
|
||||||
def test_device_sleep_on_cancellation(self):
|
def test_device_sleep_on_cancellation(self):
|
||||||
timeout_reached = False
|
|
||||||
def on_timeout():
|
|
||||||
nonlocal timeout_reached
|
|
||||||
timeout_reached = True
|
|
||||||
|
|
||||||
self.send_command('SET_CANCELLATION_ENABLED', int(False))
|
self.send_command('SET_CANCELLATION_ENABLED', int(False))
|
||||||
self.send_command('SLEEP', 1500)
|
self.send_command('SLEEP', 1500)
|
||||||
self.send_command('SCAN', 'foo-print')
|
self.send_command('SCAN', 'foo-print')
|
||||||
GLib.timeout_add(300, on_timeout)
|
|
||||||
|
|
||||||
self.start_verify(FPrint.Print.new(self.dev),
|
self.start_verify(FPrint.Print.new(self.dev),
|
||||||
identify=self.dev.supports_identify())
|
identify=self.dev.supports_identify())
|
||||||
while not timeout_reached:
|
self.wait_timeout(300)
|
||||||
ctx.iteration(False)
|
|
||||||
|
|
||||||
self.assertFalse(self._verify_completed)
|
self.assertFalse(self._verify_completed)
|
||||||
|
|
||||||
timeout_reached = False
|
|
||||||
self._cancellable.cancel()
|
self._cancellable.cancel()
|
||||||
GLib.timeout_add(300, on_timeout)
|
self.wait_timeout(300)
|
||||||
|
|
||||||
while not timeout_reached:
|
|
||||||
ctx.iteration(False)
|
|
||||||
|
|
||||||
self.assertFalse(self._verify_completed)
|
self.assertFalse(self._verify_completed)
|
||||||
self.cancel_verify()
|
self.cancel_verify()
|
||||||
|
|
Loading…
Reference in a new issue