From 167b5712ea097efcd21895be6499bcd0274a0357 Mon Sep 17 00:00:00 2001 From: Jun Siang Cheah Date: Sun, 28 Apr 2024 15:41:33 +0100 Subject: [PATCH 1/3] feat: add tests for db migration on sqlite, postgres, and mysql --- .github/workflows/integration-test.yml | 122 +++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index dfceaacc1..7d4ed68ab 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -53,3 +53,125 @@ jobs: name: compose-logs path: compose-logs.txt if-no-files-found: ignore + + migration_test: + name: Run Migration Tests + runs-on: ubuntu-latest + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + mysql: + image: mysql + env: + MYSQL_ROOT_PASSWORD: mysql + MYSQL_DATABASE: mysql + options: >- + --health-cmd "mysqladmin ping -h localhost" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 3306:3306 + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Set up uv + uses: yezz123/setup-uv@v4 + with: + uv-venv: venv + + - name: Activate virtualenv + run: | + . venv/bin/activate + echo PATH=$PATH >> $GITHUB_ENV + + - name: Install dependencies + run: | + uv pip install -r backend/requirements.txt + + - name: Test backend with SQLite + id: sqlite + run: | + cd backend + WEBUI_SECRET_KEY=secret-key GLOBAL_LOG_LEVEL=debug uvicorn main:app --port "8080" --forwarded-allow-ips '*' & + UVICORN_PID=$! + # Wait up to 20 seconds for the server to start + for i in {1..20}; do + curl -s http://localhost:8080/api/config > /dev/null && break + sleep 1 + if [ $i -eq 20 ]; then + echo "Server failed to start" + kill -9 $UVICORN_PID + exit 1 + fi + done + # Check that the server is still running after 5 seconds + sleep 5 + if ! kill -0 $UVICORN_PID; then + echo "Server has stopped" + exit 1 + fi + + + - name: Test backend with Postgres + if: success() || steps.sqlite.conclusion == 'failure' + run: | + cd backend + export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres + WEBUI_SECRET_KEY=secret-key GLOBAL_LOG_LEVEL=debug uvicorn main:app --port "8081" --forwarded-allow-ips '*' & + UVICORN_PID=$! + # Wait up to 20 seconds for the server to start + for i in {1..20}; do + curl -s http://localhost:8081/api/config > /dev/null && break + sleep 1 + if [ $i -eq 20 ]; then + echo "Server failed to start" + kill -9 $UVICORN_PID + exit 1 + fi + done + # Check that the server is still running after 5 seconds + sleep 5 + if ! kill -0 $UVICORN_PID; then + echo "Server has stopped" + exit 1 + fi + + - name: Test backend with MySQL + if: success() || steps.sqlite.conclusion == 'failure' || steps.postgres.conclusion == 'failure' + run: | + cd backend + export DATABASE_URL=mysql://root:mysql@localhost:3306/mysql + WEBUI_SECRET_KEY=secret-key GLOBAL_LOG_LEVEL=debug uvicorn main:app --port "8083" --forwarded-allow-ips '*' & + UVICORN_PID=$! + # Wait up to 20 seconds for the server to start + for i in {1..20}; do + curl -s http://localhost:8083/api/config > /dev/null && break + sleep 1 + if [ $i -eq 20 ]; then + echo "Server failed to start" + kill -9 $UVICORN_PID + exit 1 + fi + done + # Check that the server is still running after 5 seconds + sleep 5 + if ! kill -0 $UVICORN_PID; then + echo "Server has stopped" + exit 1 + fi From eed6c7194b7009f613cf6aea313e8dd07e9a83ac Mon Sep 17 00:00:00 2001 From: Jun Siang Cheah Date: Sun, 28 Apr 2024 16:55:53 +0100 Subject: [PATCH 2/3] fix: disable mysql tests --- .github/workflows/integration-test.yml | 70 +++++++++++++------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 7d4ed68ab..f2e126ed3 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -69,18 +69,18 @@ jobs: --health-retries 5 ports: - 5432:5432 - mysql: - image: mysql - env: - MYSQL_ROOT_PASSWORD: mysql - MYSQL_DATABASE: mysql - options: >- - --health-cmd "mysqladmin ping -h localhost" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - ports: - - 3306:3306 +# mysql: +# image: mysql +# env: +# MYSQL_ROOT_PASSWORD: mysql +# MYSQL_DATABASE: mysql +# options: >- +# --health-cmd "mysqladmin ping -h localhost" +# --health-interval 10s +# --health-timeout 5s +# --health-retries 5 +# ports: +# - 3306:3306 steps: - name: Checkout Repository uses: actions/checkout@v4 @@ -152,26 +152,26 @@ jobs: exit 1 fi - - name: Test backend with MySQL - if: success() || steps.sqlite.conclusion == 'failure' || steps.postgres.conclusion == 'failure' - run: | - cd backend - export DATABASE_URL=mysql://root:mysql@localhost:3306/mysql - WEBUI_SECRET_KEY=secret-key GLOBAL_LOG_LEVEL=debug uvicorn main:app --port "8083" --forwarded-allow-ips '*' & - UVICORN_PID=$! - # Wait up to 20 seconds for the server to start - for i in {1..20}; do - curl -s http://localhost:8083/api/config > /dev/null && break - sleep 1 - if [ $i -eq 20 ]; then - echo "Server failed to start" - kill -9 $UVICORN_PID - exit 1 - fi - done - # Check that the server is still running after 5 seconds - sleep 5 - if ! kill -0 $UVICORN_PID; then - echo "Server has stopped" - exit 1 - fi +# - name: Test backend with MySQL +# if: success() || steps.sqlite.conclusion == 'failure' || steps.postgres.conclusion == 'failure' +# run: | +# cd backend +# export DATABASE_URL=mysql://root:mysql@localhost:3306/mysql +# WEBUI_SECRET_KEY=secret-key GLOBAL_LOG_LEVEL=debug uvicorn main:app --port "8083" --forwarded-allow-ips '*' & +# UVICORN_PID=$! +# # Wait up to 20 seconds for the server to start +# for i in {1..20}; do +# curl -s http://localhost:8083/api/config > /dev/null && break +# sleep 1 +# if [ $i -eq 20 ]; then +# echo "Server failed to start" +# kill -9 $UVICORN_PID +# exit 1 +# fi +# done +# # Check that the server is still running after 5 seconds +# sleep 5 +# if ! kill -0 $UVICORN_PID; then +# echo "Server has stopped" +# exit 1 +# fi From f561e942442d8efa2ee3a3bf4ee55a13ace6572d Mon Sep 17 00:00:00 2001 From: Jun Siang Cheah Date: Sun, 28 Apr 2024 16:59:48 +0100 Subject: [PATCH 3/3] fix: refactor db migration tests --- .github/workflows/integration-test.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index f2e126ed3..32c331654 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -106,9 +106,12 @@ jobs: - name: Test backend with SQLite id: sqlite + env: + WEBUI_SECRET_KEY: secret-key + GLOBAL_LOG_LEVEL: debug run: | cd backend - WEBUI_SECRET_KEY=secret-key GLOBAL_LOG_LEVEL=debug uvicorn main:app --port "8080" --forwarded-allow-ips '*' & + uvicorn main:app --port "8080" --forwarded-allow-ips '*' & UVICORN_PID=$! # Wait up to 20 seconds for the server to start for i in {1..20}; do @@ -130,10 +133,13 @@ jobs: - name: Test backend with Postgres if: success() || steps.sqlite.conclusion == 'failure' + env: + WEBUI_SECRET_KEY: secret-key + GLOBAL_LOG_LEVEL: debug + DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres run: | cd backend - export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres - WEBUI_SECRET_KEY=secret-key GLOBAL_LOG_LEVEL=debug uvicorn main:app --port "8081" --forwarded-allow-ips '*' & + uvicorn main:app --port "8081" --forwarded-allow-ips '*' & UVICORN_PID=$! # Wait up to 20 seconds for the server to start for i in {1..20}; do @@ -154,10 +160,13 @@ jobs: # - name: Test backend with MySQL # if: success() || steps.sqlite.conclusion == 'failure' || steps.postgres.conclusion == 'failure' +# env: +# WEBUI_SECRET_KEY: secret-key +# GLOBAL_LOG_LEVEL: debug +# DATABASE_URL: mysql://root:mysql@localhost:3306/mysql # run: | # cd backend -# export DATABASE_URL=mysql://root:mysql@localhost:3306/mysql -# WEBUI_SECRET_KEY=secret-key GLOBAL_LOG_LEVEL=debug uvicorn main:app --port "8083" --forwarded-allow-ips '*' & +# uvicorn main:app --port "8083" --forwarded-allow-ips '*' & # UVICORN_PID=$! # # Wait up to 20 seconds for the server to start # for i in {1..20}; do