Open AlexanderWells-diamond opened 1 year ago
I can see the same thing locally. The first caget
in a new event loop will clear out the old channel connections and recreate in a new event loop. We can do the same thing by doing a purge_channel_caches
before each caget
. If we then insert a short sleep before the caget
the problem goes away:
@pytest.mark.parametrize("abc", [i for i in range(1000)])
@pytest.mark.asyncio
async def test_get_pv(abc, ioc_inline):
from aioca import purge_channel_caches
purge_channel_caches()
await asyncio.sleep(0.05)
val = await caget(LONGOUT)
assert val == 42
My guess is that ca is producing some old updates on the old event loop rather than the new, but not sure how. Will try and create a minimal reproducer using just ca.
This appears to be an issue in CA. I've reported it upstream: https://github.com/mdavidsaver/epicscorelibs/issues/16
When repeatedly running tests against a running IOC,
aioca
will occasionally report a timeout exception when trying to establish the connection, and subsequently fail the test.The code below is a minimal recreate of the issue - it starts a
softioc
IOC before the first test, runs 1000 attempts to get a PV, and then stops the IOC. Between one and three test failures are reported on my machine (although occasionally it reports 0).This was tested in a new
pipenv
environment with justaioca==1.5
,softioc==4.2.0
,pytest
, andpytest-asyncio
. Tests were executed withpipenv run pytest --tb=native -vv test.py
.The issue is exposed due to the use of event loops in pytest. By default a new loop is created for every test. The code below overrides this behaviour, and when using it shows zero errors (it also runs significantly faster):
Originally discovered by @rjwills28 while working on Coniql.