test: Fix Redis-backed test isolation across xdist runs#543
Merged
vishal-bala merged 5 commits intomainfrom Mar 27, 2026
Merged
test: Fix Redis-backed test isolation across xdist runs#543vishal-bala merged 5 commits intomainfrom
vishal-bala merged 5 commits intomainfrom
Conversation
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
nkanu17
approved these changes
Mar 27, 2026
Collaborator
nkanu17
left a comment
There was a problem hiding this comment.
This looks great to me. Like that you used redis-backed tests per-test resource names and fixing over the hnsw stuff properly, and like that the tests now clean up after themselves!
As a follow-up, it would be nice to apply the same per test naming pattern across the rest of the suite, to make isolation fully consistent.
Also this is on all of us, I realized we have so many repeated patterns or code blocks (maybe because of AI tests we all push?) that we should probs take time to clean up!
Collaborator
Author
|
🚀 PR was released in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR reduces flaky Redis-backed service tests by fixing test isolation issues in the test suite rather than changing product code.
The failures were caused by Redis state leaking across tests during
pytest -n autoruns. Several tests reused fixed Redis resource names, and some shared HNSW index fixtures created Redis indexes without deleting them. That made unrelated tests on the same xdist worker sensitive to execution order and leftover state, which explains why some matrix failures passed on retry.Problem
The main issue was cross-test persistence in Redis:
worker_id.hnsw_indexandasync_hnsw_indexcreated indexes but did not tear them down.test_app,float64 history,test_pass_through_dtype, andtest_multi_prefix.In CI, that meant one test could leave Redis resources behind for another test running later on the same worker. The result was intermittent failures that were noisy, hard to trust, and often disappeared on rerun.
Solution
This PR makes Redis-backed test resources unique per test and restores missing cleanup.
A shared pytest helper now generates per-test Redis names using the worker id plus the current test node. That helper is used in the shared search-index fixtures and in the highest-risk integration tests that previously reused fixed names. The HNSW fixtures now delete their indexes after yielding, and tests that instantiate Redis-backed objects directly now clean them up explicitly.
The semantic router tests also no longer need the existing “flaky test” skips because their Redis setup is now deterministic under unique names.
Changes
tests/conftest.pyhnsw_indexandasync_hnsw_indextest_message_history.pytest_semantic_router.pySemanticMessageHistoryandSemanticRouterinstancesScope
Verification
pytest -n autoNote
Low Risk
Low risk: changes are limited to test fixtures/assertions, mainly improving Redis resource isolation and teardown to reduce CI flakiness under
pytest-xdist. Main risk is unintended name/cleanup changes masking real failures or leaving less coverage for shared-state scenarios.Overview
Improves Redis-backed test isolation under
pytest -nby introducing aredis_test_namefixture (worker id + test node hash) and switching indices/caches/histories/routers to use per-test Redis names instead of fixed or worker-scoped ones.Adds missing teardown for HNSW index fixtures and wraps several integration tests in explicit
clear()/delete()cleanup blocks; also removes prior flaky test skips and updates a hybrid-search assertion to match the actual number of loaded docs.Written by Cursor Bugbot for commit 7e2afe8. This will update automatically on new commits. Configure here.