diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3a11171d..1d5cbc19 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,9 +7,6 @@ on: pull_request: types: [edited, ready_for_review, opened, synchronize, reopened] -env: - API_ABOUT_PAGE: "localhost:8080/api/server/about" - jobs: cache: if: | @@ -191,11 +188,7 @@ jobs: npm run coverage docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f components/serverless/docker-compose.serverless.yml build cvat_ui - - name: Running e2e tests - env: - DJANGO_SU_NAME: 'admin' - DJANGO_SU_EMAIL: 'admin@localhost.company' - DJANGO_SU_PASSWORD: '12qwaszx' + - name: Run CVAT instance for E2E testing run: | docker-compose \ -f docker-compose.yml \ @@ -203,12 +196,29 @@ jobs: -f components/serverless/docker-compose.serverless.yml \ -f tests/docker-compose.file_share.yml up -d - /bin/bash -c \ - 'while [[ $(curl -s -o /dev/null -w "%{http_code}" ${{ env.API_ABOUT_PAGE }}) != "401" ]]; do sleep 5; done' + - name: Waiting for server + env: + API_ABOUT_PAGE: "localhost:8080/api/server/about" + run: | + max_tries=60 + status_code=$(curl -s -o /tmp/server_response -w "%{http_code}" ${API_ABOUT_PAGE}) + while [[ $status_code != "401" && max_tries -gt 0 ]] + do + echo Number of attempts left: $max_tries + echo Status code of response: $status_code + + sleep 5 + status_code=$(curl -s -o /tmp/server_response -w "%{http_code}" ${API_ABOUT_PAGE}) + (( max_tries-- )) + done - docker exec -i cvat \ - /bin/bash -c \ - "echo \"from django.contrib.auth.models import User; User.objects.create_superuser('${DJANGO_SU_NAME}', '${DJANGO_SU_EMAIL}', '${DJANGO_SU_PASSWORD}')\" | python3 ~/manage.py shell" + - name: Run E2E tests + env: + DJANGO_SU_NAME: 'admin' + DJANGO_SU_EMAIL: 'admin@localhost.company' + DJANGO_SU_PASSWORD: '12qwaszx' + run: | + docker exec -i cvat /bin/bash -c "echo \"from django.contrib.auth.models import User; User.objects.create_superuser('${DJANGO_SU_NAME}', '${DJANGO_SU_EMAIL}', '${DJANGO_SU_PASSWORD}')\" | python3 ~/manage.py shell" cd ./tests npm ci diff --git a/.github/workflows/schedule.yml b/.github/workflows/schedule.yml index 443fb76d..257eed43 100644 --- a/.github/workflows/schedule.yml +++ b/.github/workflows/schedule.yml @@ -21,7 +21,7 @@ jobs: -d $(gh api /repos/${REPO}/branches/${default_branch} | jq -r '.commit.commit.author.date')) last_night_time=$(date +%s \ - -d $(gh api /repos/${REPO}/actions/workflows/caching.yml/runs | jq -r '.workflow_runs[].updated_at' | sort | tail -1)) + -d $(gh api /repos/${REPO}/actions/workflows/schedule.yml/runs | jq -r '.workflow_runs[].updated_at' | sort | tail -1)) echo ::set-output name=last_commit_time::${last_commit_time} echo ::set-output name=last_night_time::${last_night_time} @@ -130,15 +130,37 @@ jobs: pytest tests/rest_api/ pytest tests/rest_api/ --stop-services - - name: Build CVAT + - name: Run CVAT + run: | + docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f ./tests/docker-compose.email.yml -f tests/docker-compose.file_share.yml -f components/serverless/docker-compose.serverless.yml up -d --build + + - name: Waiting for server + env: + API_ABOUT_PAGE: "localhost:8080/api/server/about" + run: | + max_tries=60 + status_code=$(curl -s -o /tmp/server_response -w "%{http_code}" ${API_ABOUT_PAGE}) + while [[ $status_code != "401" && max_tries -gt 0 ]] + do + echo Number of attempts left: $max_tries + echo Status code of response: $status_code + + sleep 5 + status_code=$(curl -s -o /tmp/server_response -w "%{http_code}" ${API_ABOUT_PAGE}) + (( max_tries-- )) + done + + if [[ $status_code != "401" ]]; then + echo Response from server is incorrect, output: + cat /tmp/server_response + fi + + - name: Add user for tests env: DJANGO_SU_NAME: "admin" DJANGO_SU_EMAIL: "admin@localhost.company" DJANGO_SU_PASSWORD: "12qwaszx" - API_ABOUT_PAGE: "localhost:8080/api/server/about" run: | - docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f ./tests/docker-compose.email.yml -f tests/docker-compose.file_share.yml -f components/serverless/docker-compose.serverless.yml up -d --build - /bin/bash -c 'while [[ $(curl -s -o /dev/null -w "%{http_code}" ${API_ABOUT_PAGE}) != "401" ]]; do sleep 5; done' docker exec -i cvat /bin/bash -c "echo \"from django.contrib.auth.models import User; User.objects.create_superuser('${DJANGO_SU_NAME}', '${DJANGO_SU_EMAIL}', '${DJANGO_SU_PASSWORD}')\" | python3 ~/manage.py shell" - name: End-to-end testing diff --git a/tests/rest_api/fixtures/init.py b/tests/rest_api/fixtures/init.py index 31f519f0..9caa7908 100644 --- a/tests/rest_api/fixtures/init.py +++ b/tests/rest_api/fixtures/init.py @@ -2,6 +2,7 @@ import os.path as osp import re from http import HTTPStatus from subprocess import PIPE, CalledProcessError, run +from time import sleep import pytest import os @@ -96,10 +97,11 @@ def delete_compose_files(): def wait_for_server(): - while True: + for _ in range(60): response = requests.get(get_api_url("users/self")) if response.status_code == HTTPStatus.UNAUTHORIZED: break + sleep(5) def restore_data_volumes(): docker_cp(osp.join(CVAT_DB_DIR, "cvat_data.tar.bz2"), f"{PREFIX}_cvat_1:/tmp/cvat_data.tar.bz2")