Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working when retrying #56

Closed
janisz opened this issue Feb 27, 2020 · 1 comment
Closed

Not working when retrying #56

janisz opened this issue Feb 27, 2020 · 1 comment

Comments

@janisz
Copy link

janisz commented Feb 27, 2020

I expect following test to fail after 1 second

import pytest
from retrying import retry

@retry(
    stop_max_delay=15*1000,
    wait_fixed=1000
)
def _loop_until_condition():
    assert 1 == 0

class TestSample:
	def test_something(self):
	    _loop_until_condition()
$ time pytest test_x.py --timeout 1
platform linux -- Python 3.6.8, pytest-4.4.0, py-1.6.0, pluggy-0.9.0
plugins: timeout-1.3.4
timeout: 1.0s
timeout method: signal
timeout func_only: False
collected 1 item

test_x.py F                                                                      [100%]

===FAILURES ===
___TestSample.test_something ___

self = <test_x.TestSample object at 0x7f5d5206b198>

    def test_something(self):
>       _loop_until_condition()

test_x.py:15:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../lib/python3.6/site-packages/retrying.py:49: in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
../../lib/python3.6/site-packages/retrying.py:212: in call
    raise attempt.get()
../../lib/python3.6/site-packages/retrying.py:247: in get
    six.reraise(self.value[0], self.value[1], self.value[2])
../../lib/python3.6/site-packages/six.py:686: in reraise
    raise value
../../lib/python3.6/site-packages/retrying.py:200: in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    @retry(
        stop_max_delay=15*1000,
        wait_fixed=1000
    )
    def _loop_until_condition():
>       assert 1 == 0
E       assert 1 == 0

test_x.py:11: AssertionError

real	0m23.207s
user 0m0.963s
sys	0m0.083s

Refs: #18

@janisz janisz changed the title Not working with retrying Not working when retrying Feb 27, 2020
@flub
Copy link
Member

flub commented Mar 2, 2020

I tried reproducing this as such:

[sc]flub@powell ~
> pew mktmpenv -p python3                                                                                                                        1s 32ms
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/flub/.local/share/virtualenvs/9dade4d24cea1398/bin/python3
Also creating executable in /home/flub/.local/share/virtualenvs/9dade4d24cea1398/bin/python
Please make sure you remove any previous custom paths from your /home/flub/.pydistutils.cfg file.
Installing setuptools, pip, wheel...
done.
This is a temporary environment. It will be deleted when you exit
Launching subshell in virtual environment. Type 'exit' or 'Ctrl+D' to return.
9dade4d24cea1398 [sc]flub@powell /t/s/retrying
> cat >test.py                                                                                                                                       4ms
import pytest
from retrying import retry

@retry(
    stop_max_delay=15*1000,
    wait_fixed=1000
)
def _loop_until_condition():
    assert 1 == 0

class TestSample:
	def test_something(self):
	    _loop_until_condition()
9dade4d24cea1398 [sc]flub@powell /t/s/retrying
> pip install pytest pytest-timeout retrying                                                                                                    3s 100ms
Collecting pytest
  Using cached pytest-5.3.5-py3-none-any.whl (235 kB)
Collecting pytest-timeout
  Using cached pytest_timeout-1.3.4-py2.py3-none-any.whl (10 kB)
Collecting retrying
  Downloading retrying-1.3.3.tar.gz (10 kB)
Collecting py>=1.5.0
  Using cached py-1.8.1-py2.py3-none-any.whl (83 kB)
Collecting pluggy<1.0,>=0.12
  Using cached pluggy-0.13.1-py2.py3-none-any.whl (18 kB)
Collecting packaging
  Using cached packaging-20.1-py2.py3-none-any.whl (36 kB)
Collecting importlib-metadata>=0.12; python_version < "3.8"
  Downloading importlib_metadata-1.5.0-py2.py3-none-any.whl (30 kB)
Collecting more-itertools>=4.0.0
  Using cached more_itertools-8.2.0-py3-none-any.whl (43 kB)
Collecting attrs>=17.4.0
  Using cached attrs-19.3.0-py2.py3-none-any.whl (39 kB)
Collecting wcwidth
  Using cached wcwidth-0.1.8-py2.py3-none-any.whl (17 kB)
Collecting six>=1.7.0
  Using cached six-1.14.0-py2.py3-none-any.whl (10 kB)
Collecting pyparsing>=2.0.2
  Using cached pyparsing-2.4.6-py2.py3-none-any.whl (67 kB)
Collecting zipp>=0.5
  Downloading zipp-3.0.0-py3-none-any.whl (4.8 kB)
Building wheels for collected packages: retrying
  Building wheel for retrying (setup.py) ... done
  Created wheel for retrying: filename=retrying-1.3.3-py3-none-any.whl size=11430 sha256=13cff71c89cbd2934ef4dd52aa3a7aae590ad4873ef990daab549838b4ccdbf4
  Stored in directory: /home/flub/.cache/pip/wheels/f9/8d/8d/f6af3f7f9eea3553bc2fe6d53e4b287dad18b06a861ac56ddf
Successfully built retrying
Installing collected packages: py, zipp, importlib-metadata, pluggy, six, pyparsing, packaging, more-itertools, attrs, wcwidth, pytest, pytest-timeout, retrying
Successfully installed attrs-19.3.0 importlib-metadata-1.5.0 more-itertools-8.2.0 packaging-20.1 pluggy-0.13.1 py-1.8.1 pyparsing-2.4.6 pytest-5.3.5 pytest-timeout-1.3.4 retrying-1.3.3 six-1.14.0 wcwidth-0.1.8 zipp-3.0.0
9dade4d24cea1398 [sc]flub@powell /t/s/retrying
> pytest --timeout=1 test.py                                                                                                                    3s 901ms
================================================================= test session starts ==================================================================
platform linux -- Python 3.7.6, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: /tmp/sandbox/retrying
plugins: timeout-1.3.4
timeout: 1.0s
timeout method: signal
timeout func_only: False
collected 1 item

test.py F                                                                                                                                        [100%]

======================================================================= FAILURES =======================================================================
______________________________________________________________ TestSample.test_something _______________________________________________________________

self = <test.TestSample object at 0x7fbe3ca30750>

    def test_something(self):
>       _loop_until_condition()

test.py:13:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/flub/.local/share/virtualenvs/9dade4d24cea1398/lib/python3.7/site-packages/retrying.py:49: in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <retrying.Retrying object at 0x7fbe3ca30690>, fn = <function _loop_until_condition at 0x7fbe3ca2a830>, args = (), kwargs = {}
start_time = 1583189367445, attempt_number = 1
attempt = Attempts: 1, Error:
  File "/home/flub/.local/share/virtualenvs/9dade4d24cea1398/lib/python3.7/site-packages/retrying....gs), attempt_number, False)
  File "/tmp/sandbox/retrying/test.py", line 9, in _loop_until_condition
    assert 1 == 0

tb = (<class 'AssertionError'>, AssertionError('assert 1 == 0'), <traceback object at 0x7fbe3c998690>), delay_since_first_attempt_ms = 0, sleep = 1000

    def call(self, fn, *args, **kwargs):
        start_time = int(round(time.time() * 1000))
        attempt_number = 1
        while True:
            try:
                attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
            except:
                tb = sys.exc_info()
                attempt = Attempt(tb, attempt_number, True)

            if not self.should_reject(attempt):
                return attempt.get(self._wrap_exception)

            delay_since_first_attempt_ms = int(round(time.time() * 1000)) - start_time
            if self.stop(attempt_number, delay_since_first_attempt_ms):
                if not self._wrap_exception and attempt.has_exception:
                    # get() on an attempt with an exception should cause it to be raised, but raise just in case
                    raise attempt.get()
                else:
                    raise RetryError(attempt)
            else:
                sleep = self.wait(attempt_number, delay_since_first_attempt_ms)
                if self._wait_jitter_max:
                    jitter = random.random() * self._wait_jitter_max
                    sleep = sleep + max(0, jitter)
>               time.sleep(sleep / 1000.0)
E               Failed: Timeout >1.0s

/home/flub/.local/share/virtualenvs/9dade4d24cea1398/lib/python3.7/site-packages/retrying.py:220: Failed
================================================================== 1 failed in 1.04s ===================================================================
(1) 9dade4d24cea1398 [sc]flub@powell /t/s/retrying
>

So seems like this is working just fine? Perhaps something else in your setup is interfering.

@flub flub closed this as completed Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants