Spaces:
Build error
Build error
File size: 1,312 Bytes
3932407 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
#!/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")
|