def test_cleanup_called_on_exception(self):
		calls = random.randint(1, 10)
		cleanup = mock.Mock()
		self.set_to_fail(times=calls)
		retry_call(self.attempt, retries=calls, cleanup=cleanup, trap=Exception)
		assert cleanup.call_count == calls
		assert cleanup.called_with()
Exemple #2
0
 def test_infinite_retries(self):
     self.set_to_fail(times=999)
     cleanup = mock.Mock()
     retry_call(self.attempt,
                retries=float('inf'),
                cleanup=cleanup,
                trap=Exception)
     assert cleanup.call_count == 999
	def test_retry_call_fails(self):
		"""
		Failing more than the number of retries should
		raise the underlying error.
		"""
		self.set_to_fail(times=3)
		with pytest.raises(ValueError) as res:
			retry_call(self.attempt, retries=2, trap=ValueError)
		assert str(res.value) == 'Failed!'
Exemple #4
0
 def test_retry_call_fails(self):
     """
     Failing more than the number of retries should
     raise the underlying error.
     """
     self.set_to_fail(times=3)
     with pytest.raises(ValueError) as res:
         retry_call(self.attempt, retries=2, trap=ValueError)
     assert str(res.value) == 'Failed!'
Exemple #5
0
 def test_cleanup_called_on_exception(self):
     calls = random.randint(1, 10)
     cleanup = mock.Mock()
     self.set_to_fail(times=calls)
     retry_call(self.attempt,
                retries=calls,
                cleanup=cleanup,
                trap=Exception)
     assert cleanup.call_count == calls
     assert cleanup.called_with()
Exemple #6
0
 def test_with_arg(self):
     self.set_to_fail(times=0)
     arg = mock.Mock()
     bound = functools.partial(self.attempt, arg)
     res = retry_call(bound)
     assert res == 'Success'
     assert arg.touch.called
Exemple #7
0
    def acquire(self):
        """
        Attempt to acquire the lock every `delay` seconds until the
        lock is acquired or until `timeout` has expired.

        Raises FileLockTimeout if the timeout is exceeded.

        Errors opening the lock file (other than if it exists) are
        passed through.
        """
        self.lock = retry_call(
            self._attempt,
            retries=float('inf'),
            trap=zc.lockfile.LockError,
            cleanup=functools.partial(self._check_timeout, timing.Stopwatch()),
        )
	def test_retry_call_succeeds(self):
		self.set_to_fail(times=2)
		res = retry_call(self.attempt, retries=2, trap=ValueError)
		assert res == "Success"
	def test_retry_exception_superclass(self):
		self.set_to_fail(times=2)
		res = retry_call(self.attempt, retries=2, trap=Exception)
		assert res == "Success"
	def test_retry_multiple_exceptions(self):
		self.set_to_fail(times=2)
		errors = ValueError, NameError
		res = retry_call(self.attempt, retries=2, trap=errors)
		assert res == "Success"
Exemple #11
0
 def test_default_does_not_retry(self):
     self.set_to_fail(times=1)
     with pytest.raises(ValueError):
         retry_call(self.attempt, trap=Exception)
	def test_default_traps_nothing(self):
		self.set_to_fail(times=1)
		with pytest.raises(ValueError):
			retry_call(self.attempt, retries=1)
Exemple #13
0
 def test_default_traps_nothing(self):
     self.set_to_fail(times=1)
     with pytest.raises(ValueError):
         retry_call(self.attempt, retries=1)
Exemple #14
0
 def test_retry_exception_superclass(self):
     self.set_to_fail(times=2)
     res = retry_call(self.attempt, retries=2, trap=Exception)
     assert res == "Success"
Exemple #15
0
 def test_retry_multiple_exceptions(self):
     self.set_to_fail(times=2)
     errors = ValueError, NameError
     res = retry_call(self.attempt, retries=2, trap=errors)
     assert res == "Success"
	def test_default_does_not_retry(self):
		self.set_to_fail(times=1)
		with pytest.raises(ValueError):
			retry_call(self.attempt, trap=Exception)
Exemple #17
0
 def test_retry_call_succeeds(self):
     self.set_to_fail(times=2)
     res = retry_call(self.attempt, retries=2, trap=ValueError)
     assert res == "Success"