From 1cb7756c851498d8c353c3248034738b4c39c7a9 Mon Sep 17 00:00:00 2001 From: AndreiCautisanu <30831438+AndreiCautisanu@users.noreply.github.com> Date: Thu, 19 Sep 2024 13:26:34 +0300 Subject: [PATCH] [OPIK-67] add installer test (#273) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 Co-authored-by: Andrei Căutișanu Co-authored-by: Liya Katz --- .github/workflows/test_installer.yml | 55 +++++++++++++++++++ tests_end_to_end/installer/check_backend.sh | 23 ++++++++ .../installer/check_docker_compose_pods.sh | 26 +++++++++ tests_end_to_end/installer/test_app_status.py | 6 ++ tests_end_to_end/test_requirements.txt | 3 + 5 files changed, 113 insertions(+) create mode 100644 .github/workflows/test_installer.yml create mode 100644 tests_end_to_end/installer/check_backend.sh create mode 100644 tests_end_to_end/installer/check_docker_compose_pods.sh create mode 100644 tests_end_to_end/installer/test_app_status.py create mode 100644 tests_end_to_end/test_requirements.txt diff --git a/.github/workflows/test_installer.yml b/.github/workflows/test_installer.yml new file mode 100644 index 0000000000..ea152511ef --- /dev/null +++ b/.github/workflows/test_installer.yml @@ -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 - diff --git a/tests_end_to_end/installer/check_backend.sh b/tests_end_to_end/installer/check_backend.sh new file mode 100644 index 0000000000..3bd96fdc09 --- /dev/null +++ b/tests_end_to_end/installer/check_backend.sh @@ -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 \ No newline at end of file diff --git a/tests_end_to_end/installer/check_docker_compose_pods.sh b/tests_end_to_end/installer/check_docker_compose_pods.sh new file mode 100644 index 0000000000..5ae51dff06 --- /dev/null +++ b/tests_end_to_end/installer/check_docker_compose_pods.sh @@ -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 \ No newline at end of file diff --git a/tests_end_to_end/installer/test_app_status.py b/tests_end_to_end/installer/test_app_status.py new file mode 100644 index 0000000000..d93e940997 --- /dev/null +++ b/tests_end_to_end/installer/test_app_status.py @@ -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() + diff --git a/tests_end_to_end/test_requirements.txt b/tests_end_to_end/test_requirements.txt new file mode 100644 index 0000000000..ffe90ac21b --- /dev/null +++ b/tests_end_to_end/test_requirements.txt @@ -0,0 +1,3 @@ +pytest +playwright +pytest-playwright \ No newline at end of file