Skip to content

Commit

Permalink
ci: add tests for the examples vec-473 vec-474 vec-475 (#84)
Browse files Browse the repository at this point in the history
* ci: add prism example test action

* ci: add quote search example testing action

* ci: add basic search test action vec-473
  • Loading branch information
dwelch-spike authored Jan 31, 2025
1 parent 98ca72d commit 88acd3b
Show file tree
Hide file tree
Showing 15 changed files with 422 additions and 2 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/test-basic-search-example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Run Basic Search Tests

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
tests:
name: Basic Search Tests
runs-on: ubuntu-latest

env:
WORKING_DIR: basic-search

steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v4

# Set up Python environment
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

# Install Python dependencies
- name: Install Dependencies
working-directory: ${{ env.WORKING_DIR }}
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# Write feature keys to config files for use by AVS and Aerospike
- name: Write feature keys
working-directory: docker
env:
FEATURES_CONF : ${{secrets.FEATURES_CONF}}

run: |
echo "$FEATURES_CONF" > config/features.conf
# Run the AVS server with Docker Compose
- name: Start AVS Server
working-directory: docker
run: |
docker compose -f docker-compose.yaml up -d
# Wait for the AVS Docker Container to be Healthy
- name: Wait for Docker Container to Be Healthy
run: |
CONTAINER_NAME="aerospike-vector-search"
while [ "$(docker inspect -f '{{.State.Health.Status}}' $CONTAINER_NAME)" != "healthy" ]; do
echo "Waiting for container $CONTAINER_NAME to be healthy..."
sleep 1
done
echo "Container $CONTAINER_NAME is healthy, continuing..."
- name: Run the Basic Search
working-directory: ${{ env.WORKING_DIR }}
run: |
python search.py --port 5555
103 changes: 103 additions & 0 deletions .github/workflows/test-prism-example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Run Prism Tests

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
tests:
name: Prism Tests
runs-on: ubuntu-latest

env:
WORKING_DIR: prism-image-search

strategy:
matrix:
deployment: [waitress, docker]

steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v4

# Set up Python environment
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

# Install Python dependencies
- name: Install Dependencies
working-directory: ${{ env.WORKING_DIR }}
run: |
python -m pip install --upgrade pip
pip install -r prism/requirements.txt
pip install -r tests/requirements.txt
# Write feature keys to config files for use by AVS and Aerospike
- name: Write feature keys
working-directory: docker
env:
FEATURES_CONF : ${{secrets.FEATURES_CONF}}

run: |
echo "$FEATURES_CONF" > config/features.conf
# Run the AVS server with Docker Compose
- name: Start AVS Server
working-directory: docker
run: |
docker compose -f docker-compose.yaml up -d
# Wait for the AVS Docker Container to be Healthy
- name: Wait for Docker Container to Be Healthy
run: |
CONTAINER_NAME="aerospike-vector-search"
while [ "$(docker inspect -f '{{.State.Health.Status}}' $CONTAINER_NAME)" != "healthy" ]; do
echo "Waiting for container $CONTAINER_NAME to be healthy..."
sleep 1
done
echo "Container $CONTAINER_NAME is healthy, continuing..."
# Run the app server with waitress
- name: Start Server with Waitress
working-directory: ${{ env.WORKING_DIR }}/prism
if: matrix.deployment == 'waitress'
env:
# By default, the docker compose in /docker maps the AVS_PORT from 5000 to 5555 on localhost
AVS_PORT: 5555
run: |
nohup python -m waitress --host=127.0.0.1 --port=8080 --threads 32 prism:app &
sleep 60 # Wait for the server to be ready
# TODO come up with a better/faster way to wait for the server to be ready
# Build and run Docker container
- name: Build and Start app with Docker
working-directory: ${{ env.WORKING_DIR }}
if: matrix.deployment == 'docker'
run: |
docker build -t prism . -f Dockerfile-prism
docker run -d -p 8080:8080 --name prism \
--network svc \
-e AVS_PORT=5000 \
-e AVS_HOST=aerospike-vector-search \
prism
sleep 60 # Wait for the server to be ready
# TODO come up with a better/faster way to wait for the server to be ready
# Run Pytest tests
- name: Run Pytest
working-directory: ${{ env.WORKING_DIR }}
run: |
python -m pytest tests/e2e -s
# Cleanup Docker container (only for Docker deployment)
- name: Cleanup Docker
if: matrix.deployment == 'docker'
run: |
docker stop prism
docker rm prism
118 changes: 118 additions & 0 deletions .github/workflows/test-quote-example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Run Quote Search Tests

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
tests:
name: Quote Search Tests
runs-on: ubuntu-latest

env:
WORKING_DIR: quote-semantic-search

strategy:
matrix:
deployment: [waitress, docker, docker-preview]

steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v4

# Set up Python environment
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

# Install Python dependencies
- name: Install Dependencies
working-directory: ${{ env.WORKING_DIR }}
run: |
python -m pip install --upgrade pip
pip install -r quote-search/requirements.txt
pip install -r tests/requirements.txt
# Write feature keys to config files for use by AVS and Aerospike
- name: Write feature keys
working-directory: docker
env:
FEATURES_CONF : ${{secrets.FEATURES_CONF}}

run: |
echo "$FEATURES_CONF" > config/features.conf
# Run the AVS server with Docker Compose
- name: Start AVS Server
working-directory: docker
run: |
docker compose -f docker-compose.yaml up -d
# Wait for the AVS Docker Container to be Healthy
- name: Wait for Docker Container to Be Healthy
run: |
CONTAINER_NAME="aerospike-vector-search"
while [ "$(docker inspect -f '{{.State.Health.Status}}' $CONTAINER_NAME)" != "healthy" ]; do
echo "Waiting for container $CONTAINER_NAME to be healthy..."
sleep 1
done
echo "Container $CONTAINER_NAME is healthy, continuing..."
# Run the app server with waitress
- name: Start Server with Waitress
working-directory: ${{ env.WORKING_DIR }}/quote-search
if: matrix.deployment == 'waitress'
env:
# By default, the docker compose in /docker maps the AVS_PORT from 5000 to 5555 on localhost
AVS_PORT: 5555
run: |
nohup python -m waitress --host=127.0.0.1 --port=8080 --threads 32 quote_search:app &
sleep 60 # Wait for the server to be ready
# TODO come up with a better/faster way to wait for the server to be ready
# Build and run Docker container
- name: Build and Start app with Docker
working-directory: ${{ env.WORKING_DIR }}
if: matrix.deployment == 'docker'
run: |
docker build -t quote-search . -f Dockerfile-quote-search
docker run -d -p 8080:8080 --name quote-search \
--network svc \
-e AVS_PORT=5000 \
-e AVS_HOST=aerospike-vector-search \
-v ./container-volumes/quote-search/data:/container-volumes/quote-search/data \
quote-search
sleep 60 # Wait for the server to be ready
# TODO come up with a better/faster way to wait for the server to be ready
# Build and run preview Docker container
# The preview container copies the dataset so no volume is needed
- name: Build and Start app with preview Docker image
if: matrix.deployment == 'docker-preview'
run: |
docker build -t quote-search . -f .internal/Dockerfile-quote-search-preview
docker run -d -p 8080:8080 --name quote-search \
--network svc \
-e AVS_PORT=5000 \
-e AVS_HOST=aerospike-vector-search \
quote-search
sleep 60 # Wait for the server to be ready
# TODO come up with a better/faster way to wait for the server to be ready
# Run Pytest tests
- name: Run Pytest
working-directory: ${{ env.WORKING_DIR }}
run: |
python -m pytest tests/e2e -s
# Cleanup Docker container (only for Docker deployment)
- name: Cleanup Docker
if: matrix.deployment == 'docker' || matrix.deployment == 'docker-preview'
run: |
docker stop quote-search
docker rm quote-search
3 changes: 3 additions & 0 deletions prism-image-search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ ln -s ~/Pictures static/images/data
> If you did not use a virtualenv when installing dependencies `waitress-serve` will
> likely not be in your path.
> [!IMPORTANT]
> If Aerospike Vector Search is not running on port 5555 change the command below to match your deployment.
```shell
AVS_PORT=5555 waitress-serve --host 127.0.0.1 --port 8080 --threads 32 prism:app
```
Expand Down
1 change: 0 additions & 1 deletion prism-image-search/prism/static/images/.gitignore

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions prism-image-search/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Test Information

Pytest test suite for the AVS prism image search example application.
These tests are simple and used by the devs to verify the examples are functional.
They should not be used as a model for your production tests.

## Setup

Create a virtual environment and install the requirements in requirements.txt.
```shell
pip install -r requirements.txt
```

> [!IMPORTANT]
> Run the example app with the IMAGE_DIR environment variable pointing to your test image data. The CI tests use ../container-volumes/prism/images/static/data as it contains one image already.
Run the prism image search example app so that it listens on port 8080.
If it is not running on port 8080, you can run the tests with the --app-address option set to the correct address:port.

Then run the tests with pytest.
```shell
python -m pytest .
```
29 changes: 29 additions & 0 deletions prism-image-search/tests/e2e/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest

##########################################
###### GLOBALS
##########################################

DEFAULT_APP_ADDRESS = "127.0.0.1:8080"

##########################################
###### SUITE FLAGS
##########################################

def pytest_addoption(parser):
parser.addoption("--app-address", action="store", default=DEFAULT_APP_ADDRESS, help="app address, ip:port")


@pytest.fixture(scope='session', autouse=True)
def app(request):
return request.config.getoption("--app-address")


##########################################
###### FIXTURES
##########################################

@pytest.fixture(scope='session')
def app_url(app):
app_url = f"http://{app}"
yield app_url
12 changes: 12 additions & 0 deletions prism-image-search/tests/e2e/test_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

import requests

def test_search(app_url):

response = requests.post(app_url + "/rest/v1/search", data={"text": "aerospike"})
assert response.status_code == 200, f"Expected status code 200, but got {response.status_code}"

# by default there is 1 photo in the data dir so expect 1
results = response.json()["results"]
assert len(results) == 1, f"Expected 1 results, but got {len(results)}"
3 changes: 3 additions & 0 deletions prism-image-search/tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
requests
aerospike-vector-search
5 changes: 4 additions & 1 deletion quote-semantic-search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ python3 -m pip install -r requirements.txt
> If you did not use a virtualenv when installing dependencies `waitress-serve` will
> likely not be in your path.
> [!IMPORTANT]
> If Aerospike Vector Search is not running on port 5555 change the command below to match your deployment.
```shell
waitress-serve --host 127.0.0.1 --port 8080 --threads 32 quote_search:app
AVS_PORT=5555 waitress-serve --host 127.0.0.1 --port 8080 --threads 32 quote_search:app
```

## Performing a quote search
Expand Down
Loading

0 comments on commit 88acd3b

Please sign in to comment.