[CI] Fix race condition in test_kv_cache_events test #18169
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We observed an occasional failure on this test case:
tests/v1/engine/test_engine_core_client.py::test_kv_cache_events[True-tcp]
I believe this change should resolve it. The KV event publisher was
initializing its zmq socket in a new thread, which gives a window of
opportunity for the subscriber created in the test to try to connect too
soon, putting things in a bad state and missing the event expected.
The
time.sleep(0.1)in the test is a pretty good hint that this is aproblem. I assume whoever put that there observed this race and found
that this yield seemed to be enough to fix it. Unfortunately this sort
of thing is usually still bound to fail on occassion.
The fix here is to move zmq socket initialization back into the main
flow of control prior to creating the background thread. That way we
know it's created before the test creates the subscriber. The change
also removes the sleep, as it should no longer be necessary if this race
condition was the reason it was added originally.
Signed-off-by: Russell Bryant rbryant@redhat.com