From 4b443f71e3d41a2c0753de3f6e0f9d2e766b1900 Mon Sep 17 00:00:00 2001 From: abuzogan Date: Fri, 23 Feb 2024 11:22:07 +0100 Subject: [PATCH 1/4] waiting for postgres service to start before running test scripts and moved env variables --- backend/Dockerfile.test | 6 ------ backend/tests.yaml | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/backend/Dockerfile.test b/backend/Dockerfile.test index 46b7ac47..f975133c 100644 --- a/backend/Dockerfile.test +++ b/backend/Dockerfile.test @@ -11,11 +11,5 @@ RUN apt-get update RUN apt-get install -y --no-install-recommends python3-pip RUN pip3 install --no-cache-dir -r requirements.txt -r dev-requirements.txt -# Set environment variables -ENV POSTGRES_USER=test_user -ENV POSTGRES_PASSWORD=test_password -ENV POSTGRES_DB=test_database -ENV POSTGRES_HOST=postgres - # Command to run the tests CMD ["pytest"] \ No newline at end of file diff --git a/backend/tests.yaml b/backend/tests.yaml index 9a4bb115..43e401c9 100644 --- a/backend/tests.yaml +++ b/backend/tests.yaml @@ -7,15 +7,25 @@ services: POSTGRES_USER: test_user POSTGRES_PASSWORD: test_password POSTGRES_DB: test_database + healthcheck: + test: ["CMD-SHELL", "pg_isready -U test_user -d test_database"] + interval: 5s + timeout: 3s + retries: 3 + start_period: 5s test-runner: build: context: . dockerfile: Dockerfile.test depends_on: - - postgres + postgres: + condition: service_healthy environment: POSTGRES_HOST: postgres # Use the service name defined in Docker Compose + POSTGRES_USER: test_user + POSTGRES_PASSWORD: test_password + POSTGRES_DB: test_database volumes: - .:/app - command: ["pytest"] \ No newline at end of file + command: ["pytest"] From aa2edcd9cd50032d34804367beab28a8a3b4884d Mon Sep 17 00:00:00 2001 From: abuzogan Date: Fri, 23 Feb 2024 11:32:44 +0100 Subject: [PATCH 2/4] changed github action to run test script instead --- .github/workflows/ci-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index c0d4cfa4..e6e66232 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -37,7 +37,7 @@ jobs: working-directory: ./frontend run: npm run lint Backend-tests: - runs-on: self-hosted + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -53,7 +53,7 @@ jobs: - name: Running tests working-directory: ./backend - run: pytest + run: ./run_tests.sh - name: Run linting working-directory: ./backend From 7913d7ad01ce8e7b7fb5753aba83fad36b258c97 Mon Sep 17 00:00:00 2001 From: abuzogan Date: Fri, 23 Feb 2024 11:35:44 +0100 Subject: [PATCH 3/4] running test script with sudo --- .github/workflows/ci-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index e6e66232..8716be6a 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -53,7 +53,7 @@ jobs: - name: Running tests working-directory: ./backend - run: ./run_tests.sh + run: sudo ./run_tests.sh - name: Run linting working-directory: ./backend From 1dbabf21803467813ab23dd0d324eb9f6060f1c5 Mon Sep 17 00:00:00 2001 From: abuzogan Date: Fri, 23 Feb 2024 11:37:04 +0100 Subject: [PATCH 4/4] adding bash to run script --- .github/workflows/ci-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 8716be6a..6f9bf2c0 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -53,7 +53,7 @@ jobs: - name: Running tests working-directory: ./backend - run: sudo ./run_tests.sh + run: sudo bash ./run_tests.sh - name: Run linting working-directory: ./backend