mirror of
https://github.com/qdrant/qdrant.git
synced 2026-07-27 21:21:08 -05:00
* 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>
60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
import os
|
|
import random
|
|
import string
|
|
|
|
import jwt
|
|
from consensus_tests.utils import start_cluster
|
|
|
|
# Each pytest-xdist worker gets its own 100-port window so auth test files can
|
|
# run in parallel on different workers without binding the same port.
|
|
_worker_id = os.environ.get("PYTEST_XDIST_WORKER", "gw0")
|
|
_worker_num = int(_worker_id[2:]) if _worker_id.startswith("gw") and _worker_id[2:].isdigit() else 0
|
|
PORT_SEED = 10000 + _worker_num * 100
|
|
REST_URI = f"http://127.0.0.1:{PORT_SEED + 2}"
|
|
GRPC_URI = f"127.0.0.1:{PORT_SEED + 1}"
|
|
|
|
SECRET = "my_top_secret_key"
|
|
ALT_SECRET = "my_alternative_secret_key"
|
|
|
|
READ_ONLY_API_KEY = "boo-hoo, this can only read!"
|
|
|
|
API_KEY_HEADERS = {"Api-Key": SECRET}
|
|
API_KEY_METADATA = [("api-key", SECRET)]
|
|
READ_ONLY_API_KEY_METADATA = [("api-key", READ_ONLY_API_KEY)]
|
|
|
|
|
|
def start_jwt_protected_cluster(tmp_path, num_peers=1, extra_env=None):
|
|
base_env = {
|
|
"QDRANT__SERVICE__API_KEY": SECRET,
|
|
"QDRANT__SERVICE__ALT_API_KEY": ALT_SECRET,
|
|
"QDRANT__SERVICE__READ_ONLY_API_KEY": READ_ONLY_API_KEY,
|
|
"QDRANT__SERVICE__JWT_RBAC": "true",
|
|
"QDRANT__STORAGE__WAL__WAL_CAPACITY_MB": "1", # to speed up snapshot tests
|
|
}
|
|
extra_env = {
|
|
**base_env,
|
|
**(extra_env or {}),
|
|
}
|
|
|
|
peer_api_uris, peer_dirs, bootstrap_uri = start_cluster(
|
|
tmp_path,
|
|
num_peers=num_peers,
|
|
port_seed=PORT_SEED,
|
|
extra_env=extra_env,
|
|
headers=API_KEY_HEADERS,
|
|
)
|
|
|
|
assert REST_URI in peer_api_uris
|
|
|
|
return peer_api_uris, peer_dirs, bootstrap_uri
|
|
|
|
|
|
def encode_jwt(claims: dict, secret: str) -> str:
|
|
return jwt.encode(claims, secret, algorithm="HS256")
|
|
|
|
def decode_jwt(token: str, secret: str) -> dict:
|
|
return jwt.decode(token, secret, algorithms=["HS256"])
|
|
|
|
def random_str():
|
|
return "".join(random.choices(string.ascii_lowercase, k=10))
|