예제 #1
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()
예제 #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
예제 #3
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!'
예제 #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!'
예제 #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()
예제 #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
예제 #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()),
        )
예제 #8
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"
예제 #9
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"
예제 #10
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"
예제 #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)
예제 #12
0
	def test_default_traps_nothing(self):
		self.set_to_fail(times=1)
		with pytest.raises(ValueError):
			retry_call(self.attempt, retries=1)
예제 #13
0
 def test_default_traps_nothing(self):
     self.set_to_fail(times=1)
     with pytest.raises(ValueError):
         retry_call(self.attempt, retries=1)
예제 #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"
예제 #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"
예제 #16
0
	def test_default_does_not_retry(self):
		self.set_to_fail(times=1)
		with pytest.raises(ValueError):
			retry_call(self.attempt, trap=Exception)
예제 #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"