Skip to content

Commit

Permalink
run integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
levand committed Dec 4, 2022
1 parent 556487a commit 73b8575
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
venv
.git
examples
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ index_data
/index_data

venv
.env
.env
.chroma
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/arm64 python:3.10 AS chroma_server
FROM --platform=linux/arm64 python:3.10

#RUN apt-get update -qq
#RUN apt-get install python3.10 python3-pip -y --no-install-recommends && rm -rf /var/lib/apt/lists_/*
Expand All @@ -13,4 +13,4 @@ COPY ./ /

EXPOSE 8000

CMD ["uvicorn", "chroma.app:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers"]
CMD ["uvicorn", "chroma.app:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1", "--proxy-headers"]
19 changes: 19 additions & 0 deletions bin/integration-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -e

function cleanup {
docker-compose down --rmi local --volumes
}

trap cleanup EXIT

docker-compose up --build -d

export CHROMA_INTEGRATION_TEST=1
export CHROMA_API_IMPL=rest
export CHROMA_SERVER_HOST=localhost
export CHROMA_SERVER_HTTP_PORT=8000

python -m pytest

11 changes: 0 additions & 11 deletions bin/test

This file was deleted.

5 changes: 1 addition & 4 deletions chroma/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import chroma
from chroma.server.fastapi import FastAPI
settings = chroma.config.Settings(
chroma_db_impl="clickhouse",
clickhouse_host="clickhouse",
clickhouse_port="9000",)
settings = chroma.config.Settings()
server = FastAPI(settings)
app = server.app()
11 changes: 10 additions & 1 deletion chroma/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
import tempfile
import copy
import os
from multiprocessing import Process
import uvicorn
from requests.exceptions import ConnectionError
Expand All @@ -15,6 +16,11 @@ def local_api():
chroma_db_impl="duckdb",
chroma_cache_dir=tempfile.gettempdir()))

@pytest.fixture
def fastapi_integration_api():
return chroma.get_api() # configured by environment variables


def _build_fastapi_api():
return chroma.get_api(Settings(chroma_api_impl="rest",
chroma_server_host="localhost",
Expand Down Expand Up @@ -55,9 +61,12 @@ def fastapi_server():
yield
proc.kill()


test_apis = [local_api, fastapi_api]

if 'CHROMA_INTEGRATION_TEST' in os.environ:
print("Including integration tests")
test_apis.append(fastapi_integration_api)


@pytest.mark.parametrize('api_fixture', test_apis)
def test_heartbeat(api_fixture, request):
Expand Down
5 changes: 5 additions & 0 deletions chroma/test/test_chroma.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import unittest
import os
from unittest.mock import patch

import chroma
Expand Down Expand Up @@ -32,13 +33,15 @@ class GetAPITest(unittest.TestCase):

@patch('chroma.db.duckdb.DuckDB', autospec=True)
@patch('chroma.api.local.LocalAPI', autospec=True)
@patch.dict(os.environ, {}, clear=True)
def test_local(self, mock_api, mock_db):
api = chroma.get_api(chroma.config.Settings(chroma_cache_dir="./foo"))
assert mock_api.called
assert mock_db.called

@patch('chroma.db.duckdb.DuckDB', autospec=True)
@patch('chroma.api.celery.CeleryAPI', autospec=True)
@patch.dict(os.environ, {}, clear=True)
def test_celery(self, mock_api, mock_db):
api = chroma.get_api(chroma.config.Settings(chroma_api_impl="celery",
chroma_cache_dir="./foo",
Expand All @@ -49,6 +52,7 @@ def test_celery(self, mock_api, mock_db):


@patch('chroma.api.fastapi.FastAPI', autospec=True)
@patch.dict(os.environ, {}, clear=True)
def test_fastapi(self, mock):
api = chroma.get_api(chroma.config.Settings(chroma_api_impl="rest",
chroma_cache_dir="./foo",
Expand All @@ -58,6 +62,7 @@ def test_fastapi(self, mock):


@patch('chroma.api.arrowflight.ArrowFlightAPI', autospec=True)
@patch.dict(os.environ, {}, clear=True)
def test_arrowflight(self, mock):
api = chroma.get_api(chroma.config.Settings(chroma_api_impl="arrowflight",
chroma_cache_dir="./foo",
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ services:
build:
context: .
dockerfile: Dockerfile
target: chroma_server
volumes:
- ./:/chroma
- index_data:/index_data
command: uvicorn chroma.app:app --reload --workers 1 --host 0.0.0.0 --port 8000
environment:
- CHROMA_DB_IMPL=clickhouse
- CLICKHOUSE_HOST=clickhouse
- CLICKHOUSE_PORT=9000
- CELERY_BROKER_URL=redis://redis:6379/0
- CELERY_RESULT_BACKEND=redis://redis:6379/0
- CLICKHOUSE_TCP_PORT=9000
ports:
- 8000:8000
depends_on:
Expand Down

0 comments on commit 73b8575

Please sign in to comment.