Files
qdrant/tests/consensus_tests/create_collection_and_check.py
xzfc cf08ac68dc Switch to poetry (#4518)
* Use poetry for openapi tests

* Use poetry for consensus tests

* Use poetry for gen_storage_compat_data/populate_db.py

* Make consensus_tests scripts executable

* Use poetry for test-consensus-compose

* Cleanup

* Don't call poetry run in scripts
2024-07-08 18:17:43 +00:00

47 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse
import requests
import time
from assertions import assert_http_ok
parser = argparse.ArgumentParser("Create test collection")
parser.add_argument("collection_name")
parser.add_argument("ports", type=int, nargs="+")
args = parser.parse_args()
# Create collection
r = requests.put(
f"http://127.0.0.1:{args.ports[0]}/collections/{args.collection_name}?timeout=60", json={
"vectors": {
"size": 4,
"distance": "Dot"
},
"shard_number": 6
})
assert_http_ok(r)
# Wait
time.sleep(5)
MAX_WAIT = 30
# Check that it exists on all peers
while True:
exists = True
for port in args.ports:
r = requests.get(f"http://127.0.0.1:{port}/collections")
assert_http_ok(r)
collections = r.json()["result"]["collections"]
exists &= any(collection["name"] == args.collection_name for collection in collections)
if exists:
break
else:
# Wait until collection is created on all peers
# Consensus guarantees that collection will appear on majority of peers, but not on all of them
# So we need to wait a bit extra time
time.sleep(1)
MAX_WAIT -= 1
if MAX_WAIT <= 0:
raise Exception("Collection was not created on all peers in time")