Skip to content

Commit

Permalink
Enable running integration tests against non-localhost available inst…
Browse files Browse the repository at this point in the history
…ance (qdrant#5345)

* `QDRANT_HOST` variable is used by all openapi tests, removed its copies from
  `test_multi_vector_uint8.py`, `test_multi_vector_unnamed.py`, `test_query.py`,
  `test_shard_snapshot.py`, and `test_snapshot.py`
* Added optional `QDRANT_HOST_HEADERS` env variable to set custom HTTP headers
  in order to reach Qdrant instance behind a reverse proxy. The content of the
  variable is JSON payload, e.g. `{"host": "qdrant.local"}`
* Adapted `./tests/basic_*.sh` scripts to aware of `QDRANT_HOST_HEADERS` env variable
  • Loading branch information
pedjak authored and timvisee committed Nov 8, 2024
1 parent 300c452 commit 6f23975
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 117 deletions.
34 changes: 21 additions & 13 deletions tests/basic_api_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ set -ex

QDRANT_HOST=${QDRANT_HOST:-'localhost:6333'}

qdrant_host_headers=()

if [ -n "${QDRANT_HOST_HEADERS}" ]; then
while read h; do
qdrant_host_headers+=("-H" "$h")
done <<< $(echo "${QDRANT_HOST_HEADERS}" | jq -r 'to_entries|map("\(.key): \(.value)")[]')
fi

# cleanup collection if it exists
curl -X DELETE "http://$QDRANT_HOST/collections/test_collection" \
-H 'Content-Type: application/json' \
-H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
--fail -s | jq

# create collection
curl -X PUT "http://$QDRANT_HOST/collections/test_collection" \
-H 'Content-Type: application/json' \
-H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
--fail -s \
--data-raw '{
"vectors": {
Expand All @@ -26,34 +34,34 @@ curl -X PUT "http://$QDRANT_HOST/collections/test_collection" \
}' | jq

curl -L -X PUT "http://$QDRANT_HOST/collections/test_collection/index" \
-H 'Content-Type: application/json' \
-H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
--fail -s \
--data-raw '{
"field_name": "city",
"field_schema": "keyword"
}' | jq

curl -L -X PUT "http://$QDRANT_HOST/collections/test_collection/index" \
-H 'Content-Type: application/json' \
-H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
--fail -s \
--data-raw '{
"field_name": "count",
"field_schema": "integer"
}' | jq

curl -L -X PUT "http://$QDRANT_HOST/collections/test_collection/index" \
-H 'Content-Type: application/json' \
-H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
--fail -s \
--data-raw '{
"field_name": "coords",
"field_schema": "geo"
}' | jq

curl --fail -s "http://$QDRANT_HOST/collections/test_collection" | jq
curl --fail -s "http://$QDRANT_HOST/collections/test_collection" "${qdrant_host_headers[@]-}" | jq

# insert points
curl -L -X PUT "http://$QDRANT_HOST/collections/test_collection/points?wait=true" \
-H 'Content-Type: application/json' \
-H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
--fail -s \
--data-raw '{
"points": [
Expand All @@ -78,26 +86,26 @@ curl -L -X PUT "http://$QDRANT_HOST/collections/test_collection/points?wait=true

# retrieve point
curl -L -X GET "http://$QDRANT_HOST/collections/test_collection/points/2" \
-H 'Content-Type: application/json' \
-H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
--fail -s | jq

# retrieve points
curl -L -X POST "http://$QDRANT_HOST/collections/test_collection/points" \
-H 'Content-Type: application/json' \
-H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
--fail -s \
--data-raw '{
"ids": [1, 2]
}' | jq

SAVED_POINTS_COUNT=$(curl --fail -s "http://$QDRANT_HOST/collections/test_collection" | jq '.result.points_count')
SAVED_POINTS_COUNT=$(curl --fail -s "http://$QDRANT_HOST/collections/test_collection" "${qdrant_host_headers[@]}" | jq '.result.points_count')
[[ "$SAVED_POINTS_COUNT" == "6" ]] || {
echo 'check failed - 6 points expected'
exit 1
}

# search points
curl -L -X POST "http://$QDRANT_HOST/collections/test_collection/points/search" \
-H 'Content-Type: application/json' \
-H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
--fail -s \
--data-raw '{
"vector": [0.2,0.1,0.9,0.7],
Expand All @@ -106,7 +114,7 @@ curl -L -X POST "http://$QDRANT_HOST/collections/test_collection/points/search"

# search points batch
curl -L -X POST "http://$QDRANT_HOST/collections/test_collection/points/search/batch" \
-H 'Content-Type: application/json' \
-H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
--fail -s \
--data-raw '{
"searches": [
Expand All @@ -123,7 +131,7 @@ curl -L -X POST "http://$QDRANT_HOST/collections/test_collection/points/search/b

curl -L -X POST "http://$QDRANT_HOST/collections/test_collection/points/search" \
--fail -s \
-H 'Content-Type: application/json' \
-H 'Content-Type: application/json' "${qdrant_host_headers[@]}" \
--data-raw '{
"filter": {
"should": [
Expand Down
66 changes: 36 additions & 30 deletions tests/basic_grpc_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ set -ex
# Ensure current path is project root
cd "$(dirname "$0")/../"

QDRANT_HOST='localhost:6334'
QDRANT_HOST=${QDRANT_HOST:-'localhost:6334'}

docker_grpcurl="docker run --rm --network=host -v ${PWD}/lib/api/src/grpc/proto:/proto fullstorydev/grpcurl -plaintext -import-path /proto -proto qdrant.proto"
docker_grpcurl=("docker" "run" "--rm" "--network=host" "-v" "${PWD}/lib/api/src/grpc/proto:/proto" "fullstorydev/grpcurl" "-plaintext" "-import-path" "/proto" "-proto" "qdrant.proto")

$docker_grpcurl -d '{
if [ -n "${QDRANT_HOST_HEADERS}" ]; then
while read h; do
docker_grpcurl+=("-H" "$h")
done <<< $(echo "${QDRANT_HOST_HEADERS}" | jq -r 'to_entries|map("\(.key): \(.value)")[]')
fi

"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection"
}' $QDRANT_HOST qdrant.Collections/Delete

$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection",
"vectors_config": {
"params": {
Expand All @@ -24,9 +30,9 @@ $docker_grpcurl -d '{
}
}' $QDRANT_HOST qdrant.Collections/Create

$docker_grpcurl -d '{}' $QDRANT_HOST qdrant.Collections/List
"${docker_grpcurl[@]}" -d '{}' $QDRANT_HOST qdrant.Collections/List

$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection",
"wait": true,
"ordering": null,
Expand All @@ -51,23 +57,23 @@ $docker_grpcurl -d '{
}' $QDRANT_HOST qdrant.Points/Upsert

# Create payload index
$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection",
"field_name": "city",
"field_type": 0,
"field_index_params": { "keyword_index_params": {} },
"wait": true
}' $QDRANT_HOST qdrant.Points/CreateFieldIndex

$docker_grpcurl -d '{ "collection_name": "test_collection" }' $QDRANT_HOST qdrant.Collections/Get
"${docker_grpcurl[@]}" -d '{ "collection_name": "test_collection" }' $QDRANT_HOST qdrant.Collections/Get

$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection",
"vector": [0.2,0.1,0.9,0.7],
"limit": 3
}' $QDRANT_HOST qdrant.Points/Search

$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection",
"filter": {
"should": [
Expand All @@ -85,7 +91,7 @@ $docker_grpcurl -d '{
"limit": 3
}' $QDRANT_HOST qdrant.Points/Search

$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection",
"limit": 2,
"with_vectors": {"enable": true},
Expand All @@ -103,26 +109,26 @@ $docker_grpcurl -d '{
}
}' $QDRANT_HOST qdrant.Points/Scroll

$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection",
"with_vectors": {"enable": true},
"ids": [{ "num": 2 }, { "num": 3 }, { "num": 4 }]
}' $QDRANT_HOST qdrant.Points/Get

$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection",
"positive": [{ "num": 1 }],
"negative": [{ "num": 2 }]
}' $QDRANT_HOST qdrant.Points/Recommend

# city facet
$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection",
"key": "city"
}' $QDRANT_HOST qdrant.Points/Facet

# create alias
$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"actions": [
{
"create_alias": {
Expand All @@ -134,14 +140,14 @@ $docker_grpcurl -d '{
}' $QDRANT_HOST qdrant.Collections/UpdateAliases

# search via alias
$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_alias",
"vector": [0.2,0.1,0.9,0.7],
"limit": 3
}' $QDRANT_HOST qdrant.Points/Search

# rename alias
$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"actions": [
{
"rename_alias": {
Expand All @@ -153,14 +159,14 @@ $docker_grpcurl -d '{
}' $QDRANT_HOST qdrant.Collections/UpdateAliases

# search via renamed alias
$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "new_test_alias",
"vector": [0.2,0.1,0.9,0.7],
"limit": 3
}' $QDRANT_HOST qdrant.Points/Search

# delete alias
$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"actions": [
{
"delete_alias": {
Expand All @@ -171,14 +177,14 @@ $docker_grpcurl -d '{
}' $QDRANT_HOST qdrant.Collections/UpdateAliases

# create bool index
$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection",
"field_name": "bool_field",
"field_type": 5,
"field_index_params": { "bool_index_params": {} }
}' $QDRANT_HOST qdrant.Points/CreateFieldIndex

$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection",
"with_vectors": {"enable": false},
"with_payload": {
Expand All @@ -190,7 +196,7 @@ $docker_grpcurl -d '{
# The following must return a validation error
set +e
response=$(
$docker_grpcurl -d '{
"${docker_grpcurl[@]}" -d '{
"collection_name": "test_collection",
"recommend_points": [
{
Expand All @@ -209,20 +215,20 @@ fi
set -e

# use the reflection service to inspect the full API
$docker_grpcurl $QDRANT_HOST describe
"${docker_grpcurl[@]}" $QDRANT_HOST describe

# use the reflection service to inspect each advertised service
$docker_grpcurl $QDRANT_HOST describe qdrant.Collections
$docker_grpcurl $QDRANT_HOST describe qdrant.Points
$docker_grpcurl $QDRANT_HOST describe qdrant.Snapshots
$docker_grpcurl $QDRANT_HOST describe qdrant.Qdrant
$docker_grpcurl $QDRANT_HOST describe grpc.health.v1.Health
"${docker_grpcurl[@]}" $QDRANT_HOST describe qdrant.Collections
"${docker_grpcurl[@]}" $QDRANT_HOST describe qdrant.Points
"${docker_grpcurl[@]}" $QDRANT_HOST describe qdrant.Snapshots
"${docker_grpcurl[@]}" $QDRANT_HOST describe qdrant.Qdrant
"${docker_grpcurl[@]}" $QDRANT_HOST describe grpc.health.v1.Health

# use the reflection service to get the shape of a specific message
$docker_grpcurl $QDRANT_HOST describe qdrant.UpsertPoints
"${docker_grpcurl[@]}" $QDRANT_HOST describe qdrant.UpsertPoints

# grpc protocol compliant health check
$docker_grpcurl $QDRANT_HOST grpc.health.v1.Health/Check
"${docker_grpcurl[@]}" $QDRANT_HOST grpc.health.v1.Health/Check

#SAVED_POINTS_COUNT=$(curl --fail -s "http://$QDRANT_HOST/collections/test_collection" | jq '.result.points_count')
#[[ "$SAVED_POINTS_COUNT" == "6" ]] || {
Expand Down
Loading

0 comments on commit 6f23975

Please sign in to comment.