Skip to content

Commit

Permalink
[OPIK-67] add installer test (#273)
Browse files Browse the repository at this point in the history
* initial files

* basic app is alive test

* better file structure

* adjust wait

* fix wait script

* actually fix wait script

* delete running on push on feature branch after testing on Actions

* updated ubungu version

* busy wait scripts for both pods and backend

* properly added busy wait scripts for both pods and backend

* made sure files can be found

* bash to sh

* make it run

* was i just missing a slash this entire time?

* increase timeout on ui test

* changed check

* stop opik server step and empty line

* fixed stop step

* all good, removed on push event

---------

Co-authored-by: Andrei Căutișanu <[email protected]>
Co-authored-by: Andrei Căutișanu <[email protected]>
Co-authored-by: Liya Katz <[email protected]>
  • Loading branch information
4 people authored Sep 19, 2024
1 parent 817419d commit 1cb7756
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/test_installer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Install Local Version of Opik

on:
workflow_dispatch:

jobs:
test_installation:
runs-on: ubuntu-20.04

steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Install Opik
run: pip install ${{ github.workspace }}/sdks/python

- name: Install Test Dependencies
run: |
pip install -r ${{ github.workspace }}/tests_end_to_end/test_requirements.txt
playwright install
- name: Install Opik
run: |
cd ${{ github.workspace }}/deployment/docker-compose
docker compose up --detach
- name: Check Docker pods are up
run: |
chmod +x ./tests_end_to_end/installer/check_docker_compose_pods.sh
./tests_end_to_end/installer/check_docker_compose_pods.sh
shell: bash

- name: Check backend health
run: |
chmod +x ./tests_end_to_end/installer/check_backend.sh
./tests_end_to_end/installer/check_backend.sh
shell: bash

- name: Check app is up via the UI
run: |
pytest -v -s ${{ github.workspace }}/tests_end_to_end/installer/test_app_status.py
- name: Stop Opik server
if: always()
run: |
cd ${{ github.workspace }}/deployment/docker-compose
docker compose down
cd -
23 changes: 23 additions & 0 deletions tests_end_to_end/installer/check_backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

max_retries=12
wait_interval=5
retries=0

url="http://localhost:5173/api/health-check?name=all&type=ready"

while (( retries < max_retries ))
do
response=$(curl -s -o /dev/null -w "%{http_code}" $url)
if [[ $response -eq 200 ]]; then
echo "Backend is up and healthy!"
exit 0
else
echo "Waiting for backend to be ready... (Attempt: $((retries+1))/$max_retries, Status Code: $response)"
sleep $wait_interval
retries=$((retries+1))
fi
done

echo "Error: Backend did not respond with 200 OK after $((max_retries * wait_interval)) seconds."
exit 1
26 changes: 26 additions & 0 deletions tests_end_to_end/installer/check_docker_compose_pods.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

cd deployment/docker-compose
max_retries=5
wait_interval=3
retries=0

while [[ $retries -lt $max_retries ]]
do
containers=$(docker compose ps --status running -q)
if [ -z "$containers" ]; then
echo "Waiting for containers to be up... (Attempt: $((retries+1))/$max_retries)"
sleep $wait_interval
retries=$((retries+1))
else
echo "Containers running"
docker compose ps
break
fi
done

if [[ $retries -eq $max_retries ]]; then
echo "Containers failed to start"
docker compose ps
exit 1
fi
6 changes: 6 additions & 0 deletions tests_end_to_end/installer/test_app_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from playwright.sync_api import Page, expect

def test_app_loads(page: Page):
page.goto("http://localhost:5173/default/projects")
expect(page.get_by_role("heading", name="Projects")).to_be_visible()

3 changes: 3 additions & 0 deletions tests_end_to_end/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
playwright
pytest-playwright

0 comments on commit 1cb7756

Please sign in to comment.