[issue35760] test_asyncio: test_async_gen_asyncio_gc_aclose_09() race condition

STINNER Victor report at bugs.python.org
Thu Jan 17 09:04:25 EST 2019


New submission from STINNER Victor <vstinner at redhat.com>:

The test fails once on AMD64 Windows8.1 Non-Debug 3.x when the Python test suite is run in parallel, but pass if the test is run alone (when the system is more "idle").

https://buildbot.python.org/all/#/builders/12/builds/1898

======================================================================
FAIL: test_async_gen_asyncio_gc_aclose_09 (test.test_asyncgen.AsyncGenAsyncioTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\buildarea\3.x.ware-win81-release\build\lib\test\test_asyncgen.py", line 684, in test_async_gen_asyncio_gc_aclose_09
    self.assertEqual(DONE, 1)
AssertionError: 0 != 1


It can reproduce the failure on a very busy Windows using 2 terminals:

* python -m test -F -W -j4 test_asyncgen  test_asyncgen test_asyncgen test_asyncgen
* python -m test -j0 -r -u all 

The first command runs the test 4 times in parallel in a loop until if fails, the second command is just one way to stress the system.


The test is based on time and so has a race condition depending on the exact timing:

    def test_async_gen_asyncio_gc_aclose_09(self):
        DONE = 0

        async def gen():
            nonlocal DONE
            try:
                while True:
                    yield 1
            finally:
                await asyncio.sleep(0.01)
                await asyncio.sleep(0.01)
                DONE = 1

        async def run():
            g = gen()
            await g.__anext__()
            await g.__anext__()
            del g

            await asyncio.sleep(0.1)

        self.loop.run_until_complete(run())
        self.assertEqual(DONE, 1)

----------
components: Library (Lib), Tests
messages: 333868
nosy: vstinner
priority: normal
severity: normal
status: open
title: test_asyncio: test_async_gen_asyncio_gc_aclose_09() race condition
versions: Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35760>
_______________________________________


More information about the Python-bugs-list mailing list