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

test_antistampede fails intermittently #1536

Open
jaraco opened this issue Dec 23, 2016 · 2 comments
Open

test_antistampede fails intermittently #1536

jaraco opened this issue Dec 23, 2016 · 2 comments

Comments

@jaraco
Copy link
Member

jaraco commented Dec 23, 2016

See this test failure where test_antistampede fails with an AssertionError:

_________________________ CacheTest.test_antistampede __________________________

self = <cherrypy.test.test_caching.CacheTest testMethod=test_antistampede>

    def test_antistampede(self):

        SECONDS = 4

        slow_url = '/long_process?seconds={SECONDS}'.format(**locals())

        # We MUST make an initial synchronous request in order to create the

        # AntiStampedeCache object, and populate its selecting_headers,

        # before the actual stampede.

        self.getPage(slow_url)

        self.assertBody('success!')

        self.getPage('/clear_cache?path=' + quote(slow_url, safe=''))

        self.assertStatus(200)

    

        start = datetime.datetime.now()

    

        def run():

            self.getPage(slow_url)

            # The response should be the same every time

            self.assertBody('success!')

        ts = [threading.Thread(target=run) for i in xrange(100)]

        for t in ts:

            t.start()

        for t in ts:

            t.join()

        finish = datetime.datetime.now()

        # Allow for overhead, two seconds for slow hosts

        allowance = SECONDS + 2

>       self.assertEqualDates(start, finish, seconds=allowance)

cherrypy/test/test_caching.py:317: 

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <cherrypy.test.test_caching.CacheTest testMethod=test_antistampede>

dt1 = datetime.datetime(2016, 12, 23, 22, 18, 48, 495204)

dt2 = datetime.datetime(2016, 12, 23, 22, 18, 55, 718969), seconds = 6

    def assertEqualDates(self, dt1, dt2, seconds=None):

        """Assert abs(dt1 - dt2) is within Y seconds."""

        if seconds is None:

            seconds = self.date_tolerance

    

        if dt1 > dt2:

            diff = dt1 - dt2

        else:

            diff = dt2 - dt1

        if not diff < datetime.timedelta(seconds=seconds):

            raise AssertionError('%r and %r are not within %r seconds.' %

>                                (dt1, dt2, seconds))

E           AssertionError: datetime.datetime(2016, 12, 23, 22, 18, 48, 495204) and datetime.datetime(2016, 12, 23, 22, 18, 55, 718969) are not within 6 seconds.

cherrypy/test/helper.py:403: AssertionError
@mgorny
Copy link
Contributor

mgorny commented Jul 11, 2022

Now that xfail_strict has been enabled in 565c181, this XFAIL is causing test failure when the test passes (and it seems to pass for me all the time).

jaraco added a commit that referenced this issue Jul 11, 2022
@webknjaz
Copy link
Member

@mgorny @jaraco FYI for flaky tests, the right solution is to have @pytest.mark.xfail(..., strict=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants