Skip to content

Commit

Permalink
fix tests (#1892)
Browse files Browse the repository at this point in the history
* fix tests

* fix test.yml

* chore: Add logging for sending HTTP messages to Valhalla

* fix tests 2

* install minio

* fix

* idk

* idk

* add logging

* more logs

* fix claude

* more logs

* more logging

* more logs

* gateway not hitting jawn?

* add more logs

* add more logging

* remove failed error

* wait for jawn

* remove logs, start jawn earlier

* fix stuff add logs

* fix async log headers

* Remove logs

* remove unused using

* remove new line

* fix idk

* fix tests.... zzz

* good now

* add minio
  • Loading branch information
colegottdank authored May 16, 2024
1 parent c13789d commit dd7195f
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 156 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ jobs:
mkdir -p ~/test-logs
cd worker
npm install
- name: Run Jawn
working-directory: valhalla/jawn
env:
SUPABASE_CREDS: '{"url": "http://localhost:54321", "service_role_key": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU"}'
SUPABASE_DATABASE_URL: "postgresql://postgres:postgres@localhost:54322/postgres"
VERCEL_ENV: "development"
S3_ENDPOINT: "http://localhost:9000"
S3_ACCESS_KEY: "minioadmin"
S3_SECRET_KEY: "minioadmin"
S3_BUCKET_NAME: "request-response-storage"
run: |
yarn
yarn dev > ~/test-logs/jawn.log &
- name: Start proxy worker
run: |
cd worker
Expand Down Expand Up @@ -192,7 +205,14 @@ jobs:
run: supabase start db,api
- name: Install python dependencies
run: |
pip install requests pytest psycopg2 python-dotenv helicone httpx
pip install requests pytest psycopg2 python-dotenv helicone httpx minio
- name: Wait for Jawn
run: |
echo "Waiting for Jawn to be ready..."
while ! curl -s http://localhost:8585/healthcheck; do
echo "Waiting for Jawn to be ready..."
sleep 5
done
- name: Run integration tests
working-directory: tests
env:
Expand Down
204 changes: 203 additions & 1 deletion helicone-python/poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion helicone-python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ python = ">=3.8.1"
openai = "^0.27.0"
lockfile = "^0.12.2"
pyhumps = "^3.8.0"
minio = "^7.2.7"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
python-dotenv = "^1.0.0"
psycopg2 = "^2.9.9"
psycopg2 = "^2.9.9"
36 changes: 30 additions & 6 deletions helicone-python/tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import requests
from dotenv import load_dotenv
from psycopg2.extras import DictCursor
import json
from minio import Minio

from helicone.globals import helicone_global
from helicone.globals.helicone import helicone_global
Expand All @@ -17,6 +19,7 @@
helicone_global.base_url = "http://127.0.0.1:8788"
helicone_global.api_key = "sk-helicone-aizk36y-5yue2my-qmy5tza-n7x3aqa"
helicone_global.proxy_url = "http://127.0.0.1:8787/v1"
org_id = '83635a30-5ba6-41a8-8cc6-fb7df941b24a'


def connect_to_db():
Expand All @@ -38,6 +41,27 @@ def fetch_from_db(query, params=None):
conn.close()
return results

def get_path(organizationId, requestId):
return f"organizations/{organizationId}/requests/{requestId}/request_response_body"

def fetch_from_minio(object_path):
minioClient = Minio(
"localhost:9000",
access_key="minioadmin",
secret_key="minioadmin",
secure=False
)
# Fetch the object from MinIO
print("Fetching object from MinIO with path:", object_path) # Add this line to debug

data = minioClient.get_object("request-response-storage", object_path)

# Read the data returned by the server
file_data = data.read()
data.close()

return json.loads(file_data.decode('utf-8'))


def insert_into_db(query, params):
# Construct the query
Expand Down Expand Up @@ -89,15 +113,15 @@ def test_openai_async():

time.sleep(3) # Give some time for the async logging to complete

query = "SELECT * FROM properties INNER JOIN request ON properties.request_id = request.id WHERE key = 'requestid' AND value = %s LIMIT 1"
request_data = fetch_from_db(query, (requestId,))
request_data = fetch_from_db("SELECT * FROM public.request WHERE properties @> %s", (json.dumps({"requestid": requestId}),))
assert request_data, "Request data not found in the database for the given property request id"

latest_request = request_data[0]
assert message_content in latest_request["body"]["messages"][
0]["content"], "Request not found in the database"
bodies = fetch_from_minio(get_path(org_id, request_data[0]["id"]))
assert bodies, "Request data not found in the database for the given property request id"
assert message_content in bodies["request"]["messages"][0]["content"], "Request not found in the database"
assert bodies["response"]["choices"], "Response data not found in the database for the given request ID"

query = "SELECT * FROM response WHERE request = %s LIMIT 1"
response_data = fetch_from_db(query, (latest_request["id"],))
response_data = fetch_from_db(query, (request_data[0]["id"],))
assert response_data, "Response data not found in the database for the given request ID"
print("passed")
Loading

0 comments on commit dd7195f

Please sign in to comment.