Files
qdrant/tests/consensus_tests/test_recover_dead_node.py
qdrant-cloud-bot 242c7dfa0a ci: parallelize consensus tests with pytest-xdist (#8717)
* ci: parallelize consensus tests with pytest-xdist

Enable pytest-xdist for consensus_tests to run tests across multiple
workers in parallel, significantly reducing CI wall time (~20min → ~5-7min).

Changes:
- Add `-n auto --dist=loadfile` to the consensus test pytest invocation
- Remove hardcoded port_seed from tests that don't need fixed ports for
  restart/rejoin (test_order_by, test_consensus_compaction,
  test_named_vector_crud, test_listener_node)
- Give test_cluster_rejoin its own PORT_SEED=15000 to avoid port
  conflicts with auth tests (PORT_SEED=10000)
- Derive restart ports from killed PeerProcess objects instead of
  hardcoded arithmetic where possible
- Add xdist_group("auth") marker to auth test files to ensure they
  run on the same worker (they share PORT_SEED=10000)

Made-with: Cursor

* fix: remove remaining hardcoded port_seed=20000 causing parallel test conflicts

8 test files were using port_seed=20000 as a positional argument to
start_cluster(), which was missed in the initial change. When running
in parallel with pytest-xdist, multiple workers would try to bind to
the same port range (20000-20x02), causing port conflicts and cascading
test failures.

Also remove port_seed=23000 from test_snapshot_recovery_kill.py since
it doesn't need fixed ports for restart.

Made-with: Cursor

* fix: use saved port for restart in test_two_follower_nodes_down

The test was restarting killed peers on hardcoded ports (20200/20100)
that previously matched port_seed=20000. After switching to random
ports, the restart ports no longer match the original peer ports,
causing raft state URI mismatches and peer startup failures.

Save the p2p_port from the killed PeerProcess and reuse it for restart.

Made-with: Cursor

* Reuse p2p ports when restarting killed peers in consensus tests

When a peer is killed and restarted with random ports, it gets a new
consensus URI. The cluster needs a Raft operation to update this URI,
which under CPU contention from parallel test workers can exceed the
30-second timeout. Fix by capturing each peer's p2p_port before killing
and reusing it on restart, so the URI stays the same and no consensus
update is needed.

Made-with: Cursor

* A few improvements for parallel runs (#8731)

* fix: make auth tests' PORT_SEED per-worker to avoid port collisions
* ci: improve failure visibility for parallel consensus tests
* Three small changes to make hangs, interleaved output, and coverage runs behave predictably under pytest-xdist
* fix: two test bugs surfaced by parallel runs and revert drop PR_SET_PDEATHSIG helper
* fix: wait for count convergence in test_triple_replication
* fix: clean leaked peer processes at test start

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Cursor Agent <agent@cursor.com>
Co-authored-by: tellet-q <166374656+tellet-q@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 13:47:29 +02:00

118 lines
4.1 KiB
Python

import pathlib
from .utils import *
from .assertions import assert_http_ok
N_PEERS = 3
N_SHARDS = 4
N_REPLICA = 2
def upsert_points(peer_url, city):
# Create points in first peer's collection
r_batch = requests.put(
f"{peer_url}/collections/test_collection/points?wait=true", json={
"points": [
{"id": 1, "vector": [0.05, 0.61, 0.76, 0.74], "payload": {"city": city}},
{"id": 2, "vector": [0.19, 0.81, 0.75, 0.11], "payload": {"city": city}},
{"id": 3, "vector": [0.36, 0.55, 0.47, 0.94], "payload": {"city": city}},
{"id": 4, "vector": [0.18, 0.01, 0.85, 0.80], "payload": {"city": city}},
{"id": 5, "vector": [0.24, 0.18, 0.22, 0.44], "payload": {"city": city}},
{"id": 6, "vector": [0.35, 0.08, 0.11, 0.44], "payload": {"city": city}},
{"id": 7, "vector": [0.45, 0.07, 0.21, 0.04], "payload": {"city": city}},
{"id": 8, "vector": [0.75, 0.18, 0.91, 0.48], "payload": {"city": city}},
{"id": 9, "vector": [0.30, 0.01, 0.10, 0.12], "payload": {"city": city}},
{"id": 10, "vector": [0.95, 0.8, 0.17, 0.19], "payload": {"city": city}},
]
})
assert_http_ok(r_batch)
def create_collection(peer_url, collection="test_collection", timeout=10):
# Create collection in first peer
r_batch = requests.put(
f"{peer_url}/collections/{collection}?timeout={timeout}", json={
"vectors": {
"size": 4,
"distance": "Dot"
},
"shard_number": N_SHARDS,
"replication_factor": N_REPLICA,
})
assert_http_ok(r_batch)
def search(peer_url, city):
q = {
"vector": [0.2, 0.1, 0.9, 0.7],
"top": 10,
"with_vector": False,
"with_payload": True,
"filter": {
"must": [
{
"key": "city",
"match": {"value": city}
}
]
}
}
r_search = requests.post(f"{peer_url}/collections/test_collection/points/search", json=q)
assert_http_ok(r_search)
return r_search.json()["result"]
def test_recover_dead_node(tmp_path: pathlib.Path):
assert_project_root()
peer_api_uris, peer_dirs, bootstrap_uri = start_cluster(tmp_path, N_PEERS)
create_collection(peer_api_uris[0])
wait_collection_exists_and_active_on_all_peers(collection_name="test_collection", peer_api_uris=peer_api_uris)
upsert_points(peer_api_uris[0], "Paris")
search_result = search(peer_api_uris[0], "Paris")
assert len(search_result) > 0
# Kill last peer
p = processes.pop()
restart_port = p.p2p_port
p.kill()
# Validate search works with the dead node
search_result = search(peer_api_uris[0], "Paris")
assert len(search_result) > 0
# Validate upsert works with the dead node
upsert_points(peer_api_uris[0], "Berlin")
# Assert that there are dead replicas
wait_for_some_replicas_not_active(peer_api_uris[0], "test_collection")
# Assert all records were changed
search_result = search(peer_api_uris[0], "Paris")
assert len(search_result) == 0
# Apply cluster update operation to leaving part of the cluster
# 2 nodes majority should be enough for applying the status
create_collection(peer_api_uris[0], "test_collection2", timeout=5)
new_url = start_peer(peer_dirs[-1], "peer_0_restarted.log", bootstrap_uri, port=restart_port)
# Wait for cluster to recover dead peers
wait_for_all_replicas_active(peer_api_uris[0], "test_collection")
# Assert all records were changed
search_result = search(peer_api_uris[0], "Paris")
assert len(search_result) == 0
# Assert all records were changed
search_result = search(peer_api_uris[0], "Berlin")
assert len(search_result) > 0
# Assert the replication is consistent regardless of the entry point.
assert search(peer_api_uris[0], "Paris") == search(new_url, "Paris")
wait_collection_on_all_peers("test_collection2", peer_api_uris[:-2] + [new_url])