-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: added unit tests for ci/cd associated with reranking pg comp
- Loading branch information
1 parent
ed9d79f
commit 904b788
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/bash | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -x | ||
|
||
WORKPATH=$(dirname "$PWD") | ||
ip_address=$(hostname -I | awk '{print $1}') | ||
function build_docker_images() { | ||
cd $WORKPATH | ||
docker build --no-cache --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -t opea/reranking-predictionguard:comps -f comps/reranks/predictionguard/Dockerfile . | ||
if [ $? -ne 0 ]; then | ||
echo "opea/reranking-predictionguard built fail" | ||
exit 1 | ||
else | ||
echo "opea/reranking-predictionguard built successful" | ||
fi | ||
} | ||
|
||
function start_service() { | ||
predictionguard_service_port=9000 | ||
unset http_proxy | ||
|
||
docker run -d --name="test-comps-reranking-predictionguard-server" \ | ||
-p ${predictionguard_service_port}:9000 \ | ||
--ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy \ | ||
-e PREDICTIONGUARD_API_KEY=${PREDICTIONGUARD_API_KEY} \ | ||
opea/reranking-predictionguard:comps | ||
|
||
sleep 1m | ||
} | ||
|
||
function validate_microservice() { | ||
predictionguard_service_port=9000 | ||
result=$(http_proxy="" curl http://${ip_address}:${predictionguard_service_port}/v1/reranking\ | ||
-X POST \ | ||
-d '{"initial_query":"What is Deep Learning?", "retrieved_docs": [{"text":"Deep Learning is not..."}, {"text":"Deep learning is..."}]}' \ | ||
-H 'Content-Type: application/json') | ||
if [[ $result == *"reranked_docs"* ]]; then | ||
echo "Result correct." | ||
else | ||
echo "Result wrong. Received was $result" | ||
docker logs test-comps-reranking-predictionguard-server | ||
exit 1 | ||
fi | ||
} | ||
|
||
function stop_docker() { | ||
cid=$(docker ps -aq --filter "name=test-comps-rerank*") | ||
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi | ||
} | ||
|
||
function main() { | ||
|
||
stop_docker | ||
|
||
build_docker_images | ||
start_service | ||
|
||
validate_microservice | ||
|
||
stop_docker | ||
echo y | docker system prune | ||
|
||
} | ||
|
||
main |