def test_verify(self, wait_for_true_mock): self.checkers[0].check.return_value = False wait_for_true_mock.side_effect = errors.TimeoutError() with self.assertRaisesRegexp(errors.UpgradeVerificationError, 'Failed to run services \[1\]'): self.verifier.verify()
def wait_for_true(check, timeout=60, interval=0.5): """Execute command with retries :param check: callable object :param timeout: timeout :returns: result of call method :raises TimeoutError: """ start_time = time.time() while True: result = check() if result: return result if time.time() - start_time > timeout: raise errors.TimeoutError( 'Failed to execute ' 'command with timeout {0}'.format(timeout)) time.sleep(interval)