Reduce number of test cases (#24)

main
Kirill Sizov 4 years ago committed by GitHub
parent 391370e99e
commit 561f4e299d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,9 +16,11 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-python@v2 - uses: actions/setup-python@v2
with: with:
python-version: '3.8' python-version: '3.8'
- name: Getting SHA from the default branch - name: Getting SHA from the default branch
id: get-sha id: get-sha
run: | run: |
@ -36,6 +38,7 @@ jobs:
echo ::set-output name=default_branch::${DEFAULT_BRANCH} echo ::set-output name=default_branch::${DEFAULT_BRANCH}
echo ::set-output name=sha::${SHA} echo ::set-output name=sha::${SHA}
- name: Waiting a cache creation in the default branch - name: Waiting a cache creation in the default branch
if: ${{ github.ref_name != 'develop' }} if: ${{ github.ref_name != 'develop' }}
run: | run: |
@ -69,13 +72,22 @@ jobs:
echo "Number of attempts expired!" echo "Number of attempts expired!"
echo "Probably the creation of the cache is not yet complete. Will continue working without the cache." echo "Probably the creation of the cache is not yet complete. Will continue working without the cache."
fi fi
- name: Getting CVAT server cache from the default branch - name: Getting CVAT server cache from the default branch
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: /tmp/cvat_cache_server path: /tmp/cvat_cache_server
key: ${{ runner.os }}-build-server-${{ steps.get-sha.outputs.sha }} key: ${{ runner.os }}-build-server-${{ steps.get-sha.outputs.sha }}
- name: Getting CVAT UI cache from the default branch
uses: actions/cache@v2
with:
path: /tmp/cvat_cache_ui
key: ${{ runner.os }}-build-ui-${{ steps.get-sha.outputs.sha }}
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1.1.2 uses: docker/setup-buildx-action@v1.1.2
- name: Building CVAT server image - name: Building CVAT server image
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
@ -84,11 +96,22 @@ jobs:
cache-from: type=local,src=/tmp/cvat_cache_server cache-from: type=local,src=/tmp/cvat_cache_server
tags: openvino/cvat_server:latest tags: openvino/cvat_server:latest
load: true load: true
- name: Building CVAT UI image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.ui
cache-from: type=local,src=/tmp/cvat_cache_ui
tags: openvino/cvat_ui:latest
load: true
- name: Running OPA tests - name: Running OPA tests
run: | run: |
curl -L -o opa https://openpolicyagent.org/downloads/v0.34.2/opa_linux_amd64_static curl -L -o opa https://openpolicyagent.org/downloads/v0.34.2/opa_linux_amd64_static
chmod +x ./opa chmod +x ./opa
./opa test cvat/apps/iam/rules ./opa test cvat/apps/iam/rules
- name: Running REST API tests - name: Running REST API tests
env: env:
API_ABOUT_PAGE: "localhost:8080/api/server/about" API_ABOUT_PAGE: "localhost:8080/api/server/about"
@ -98,16 +121,22 @@ jobs:
run: | run: |
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f components/serverless/docker-compose.serverless.yml -f components/analytics/docker-compose.analytics.yml -f tests/rest_api/docker-compose.minio.yml up -d docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f components/serverless/docker-compose.serverless.yml -f components/analytics/docker-compose.analytics.yml -f tests/rest_api/docker-compose.minio.yml up -d
/bin/bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' ${API_ABOUT_PAGE})" != "401" ]]; do sleep 5; done' /bin/bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' ${API_ABOUT_PAGE})" != "401" ]]; do sleep 5; done'
pip3 install --user -r tests/rest_api/requirements.txt pip3 install --user -r tests/rest_api/requirements.txt
pytest tests/rest_api/ pytest tests/rest_api/ -k 'GET'
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f components/serverless/docker-compose.serverless.yml -f components/analytics/docker-compose.analytics.yml -f tests/rest_api/docker-compose.minio.yml down -v docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f components/serverless/docker-compose.serverless.yml -f components/analytics/docker-compose.analytics.yml -f tests/rest_api/docker-compose.minio.yml down -v
- name: Running unit tests - name: Running unit tests
env: env:
HOST_COVERAGE_DATA_DIR: ${{ github.workspace }} HOST_COVERAGE_DATA_DIR: ${{ github.workspace }}
CONTAINER_COVERAGE_DATA_DIR: "/coverage_data" CONTAINER_COVERAGE_DATA_DIR: "/coverage_data"
run: | run: |
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'coverage run -a manage.py test cvat/apps utils/cli && mv .coverage ${CONTAINER_COVERAGE_DATA_DIR}' docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'cd cvat-data && npm ci && cd ../cvat-core && npm ci && npm run test && mv ./reports/coverage/lcov.info ${CONTAINER_COVERAGE_DATA_DIR} && chmod a+rwx ${CONTAINER_COVERAGE_DATA_DIR}/lcov.info' -c 'coverage run -a manage.py test cvat/apps utils/cli -k 'tasks_id' -k 'lambda' -k 'share' && mv .coverage ${CONTAINER_COVERAGE_DATA_DIR}'
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
-c 'cd cvat-data && npm ci && cd ../cvat-core && npm ci && npm run test && mv ./reports/coverage/lcov.info ${CONTAINER_COVERAGE_DATA_DIR} && chmod a+rwx ${CONTAINER_COVERAGE_DATA_DIR}/lcov.info'
- name: Uploading code coverage results as an artifact - name: Uploading code coverage results as an artifact
if: github.ref == 'refs/heads/develop' if: github.ref == 'refs/heads/develop'
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
@ -126,9 +155,10 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
specs: ['actions_tasks', 'actions_tasks2', 'actions_tasks3', 'actions_objects', 'actions_objects2', 'actions_users', 'actions_projects_models', 'actions_organizations', 'canvas3d_functionality', 'canvas3d_functionality_2', 'issues_prs', 'issues_prs2'] specs: ['canvas3d_functionality', 'actions']
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Getting SHA from the default branch - name: Getting SHA from the default branch
id: get-sha id: get-sha
run: | run: |
@ -146,6 +176,7 @@ jobs:
echo ::set-output name=default_branch::${DEFAULT_BRANCH} echo ::set-output name=default_branch::${DEFAULT_BRANCH}
echo ::set-output name=sha::${SHA} echo ::set-output name=sha::${SHA}
- name: Waiting a cache creation in the default branch - name: Waiting a cache creation in the default branch
run: | run: |
URL_runs="https://api.github.com/repos/${{ github.repository }}/actions/workflows/cache.yml/runs" URL_runs="https://api.github.com/repos/${{ github.repository }}/actions/workflows/cache.yml/runs"
@ -179,21 +210,26 @@ jobs:
echo "Number of attempts expired!" echo "Number of attempts expired!"
echo "Probably the creation of the cache is not yet complete. Will continue working without the cache." echo "Probably the creation of the cache is not yet complete. Will continue working without the cache."
fi fi
- name: Getting CVAT server cache from the default branch - name: Getting CVAT server cache from the default branch
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: /tmp/cvat_cache_server path: /tmp/cvat_cache_server
key: ${{ runner.os }}-build-server-${{ steps.get-sha.outputs.sha }} key: ${{ runner.os }}-build-server-${{ steps.get-sha.outputs.sha }}
- name: Getting cache CVAT UI from the default branch
- name: Getting CVAT UI cache from the default branch
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: /tmp/cvat_cache_ui path: /tmp/cvat_cache_ui
key: ${{ runner.os }}-build-ui-${{ steps.get-sha.outputs.sha }} key: ${{ runner.os }}-build-ui-${{ steps.get-sha.outputs.sha }}
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: '16.x' node-version: '16.x'
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1.1.2 uses: docker/setup-buildx-action@v1.1.2
- name: Building CVAT server image - name: Building CVAT server image
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
@ -202,6 +238,7 @@ jobs:
cache-from: type=local,src=/tmp/cvat_cache_server cache-from: type=local,src=/tmp/cvat_cache_server
tags: openvino/cvat_server:latest tags: openvino/cvat_server:latest
load: true load: true
- name: Building CVAT UI image - name: Building CVAT UI image
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
@ -210,12 +247,14 @@ jobs:
cache-from: type=local,src=/tmp/cvat_cache_ui cache-from: type=local,src=/tmp/cvat_cache_ui
tags: openvino/cvat_ui:latest tags: openvino/cvat_ui:latest
load: true load: true
- name: Instrumentation of the code then rebuilding the CVAT UI - name: Instrumentation of the code then rebuilding the CVAT UI
if: github.ref == 'refs/heads/develop' if: github.ref == 'refs/heads/develop'
run: | run: |
npm ci npm ci
npm run coverage npm run coverage
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f components/serverless/docker-compose.serverless.yml build cvat_ui 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 - name: Running e2e tests
env: env:
DJANGO_SU_NAME: 'admin' DJANGO_SU_NAME: 'admin'
@ -226,38 +265,51 @@ jobs:
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f components/serverless/docker-compose.serverless.yml -f tests/docker-compose.file_share.yml up -d docker-compose -f docker-compose.yml -f docker-compose.dev.yml -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}" ${API_ABOUT_PAGE}) != "401" ]]; do sleep 5; done' /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" 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 cd ./tests
npm ci npm ci
if [[ ${{ github.ref }} == 'refs/heads/develop' ]]; then
if [ ${{ matrix.specs }} == 'canvas3d_functionality' ] || [ ${{ matrix.specs }} == 'canvas3d_functionality_2' ]; then if [ ${{ matrix.specs }} == 'canvas3d_functionality' ]; then
npx cypress run --headed --browser chrome --config-file cypress_canvas3d.json --spec 'cypress/integration/${{ matrix.specs }}/**/*.js,cypress/integration/remove_users_tasks_projects_organizations.js' # Choosing 5 test files
else selected_files=$(find ./cypress/integration | grep -e 'case.*\|issue.*' | grep js | grep 3d | sort | head -5 | tr '\n' ',')
npx cypress run --browser chrome --spec 'cypress/integration/${{ matrix.specs }}/**/*.js,cypress/integration/remove_users_tasks_projects_organizations.js'
fi npx cypress run \
mv ./.nyc_output/out.json ./.nyc_output/out_${{ matrix.specs }}.json --headed \
--browser chrome \
--env coverage=false \
--config-file cypress_canvas3d.json \
--spec "${selected_files} cypress/integration/remove_users_tasks_projects_organizations.js"
else else
if [ ${{ matrix.specs }} == 'canvas3d_functionality' ] || [ ${{ matrix.specs }} == 'canvas3d_functionality_2' ]; then # Choosing 20 test files
npx cypress run --headed --browser chrome --env coverage=false --config-file cypress_canvas3d.json --spec 'cypress/integration/${{ matrix.specs }}/**/*.js,cypress/integration/remove_users_tasks_projects_organizations.js' find ./cypress/integration | grep -e 'case.*\|issue.*' | grep js | sed '/.*3d.*/d' | sort > test_files
else selected_files=$({ head -10; tail -10;} < test_files | tr '\n' ',')
npx cypress run --browser chrome --env coverage=false --spec 'cypress/integration/${{ matrix.specs }}/**/*.js,cypress/integration/remove_users_tasks_projects_organizations.js' rm test_files
fi
npx cypress run \
--browser chrome \
--env coverage=false \
--spec "${selected_files} cypress/integration/remove_users_tasks_projects_organizations.js"
fi fi
- name: Creating a log file from "cvat" container logs - name: Creating a log file from "cvat" container logs
if: failure() if: failure()
run: | run: |
docker logs cvat > ${{ github.workspace }}/tests/cvat_${{ matrix.specs }}.log docker logs cvat > ${{ github.workspace }}/tests/cvat_${{ matrix.specs }}.log
- name: Uploading cypress screenshots as an artifact - name: Uploading cypress screenshots as an artifact
if: failure() if: failure()
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: cypress_screenshots_${{ matrix.specs }} name: cypress_screenshots_${{ matrix.specs }}
path: ${{ github.workspace }}/tests/cypress/screenshots path: ${{ github.workspace }}/tests/cypress/screenshots
- name: Uploading "cvat" container logs as an artifact - name: Uploading "cvat" container logs as an artifact
if: failure() if: failure()
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: cvat_container_logs name: cvat_container_logs
path: ${{ github.workspace }}/tests/cvat_${{ matrix.specs }}.log path: ${{ github.workspace }}/tests/cvat_${{ matrix.specs }}.log
- name: Uploading code coverage results as an artifact - name: Uploading code coverage results as an artifact
if: github.ref == 'refs/heads/develop' if: github.ref == 'refs/heads/develop'
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2

@ -35,7 +35,7 @@ def init_test_db():
_run('docker exec cvat_db psql -U root -d postgres -v from=test_db -v to=cvat -f restore.sql') _run('docker exec cvat_db psql -U root -d postgres -v from=test_db -v to=cvat -f restore.sql')
_run('docker exec cvat_db dropdb test_db') _run('docker exec cvat_db dropdb test_db')
@pytest.fixture(scope='function', autouse=True) @pytest.fixture(scope='function')
def restore(): def restore():
_run('docker exec cvat_db psql -U root -d postgres -v from=test_db -v to=cvat -f restore.sql') _run('docker exec cvat_db psql -U root -d postgres -v from=test_db -v to=cvat -f restore.sql')

@ -59,6 +59,7 @@ class TestGetCloudStorage:
self._test_cannot_see(username, storage_id, org_id=org_id) self._test_cannot_see(username, storage_id, org_id=org_id)
@pytest.mark.usefixtures("restore")
class TestPostCloudStorage: class TestPostCloudStorage:
_SPEC = { _SPEC = {
'provider_type': 'AWS_S3_BUCKET', 'provider_type': 'AWS_S3_BUCKET',
@ -120,6 +121,7 @@ class TestPostCloudStorage:
else: else:
self._test_cannot_create(username, self._SPEC, org_id=org_id) self._test_cannot_create(username, self._SPEC, org_id=org_id)
@pytest.mark.usefixtures("restore")
class TestPatchCloudStorage: class TestPatchCloudStorage:
_SPEC = { _SPEC = {
'display_name': 'New display name', 'display_name': 'New display name',

@ -6,6 +6,7 @@ from http import HTTPStatus
import pytest import pytest
from .utils.config import post_method from .utils.config import post_method
@pytest.mark.usefixtures("restore")
class TestCreateInvitations: class TestCreateInvitations:
def _test_post_invitation_201(self, user, data, invitee, **kwargs): def _test_post_invitation_201(self, user, data, invitee, **kwargs):
response = post_method(user, 'invitations', data, **kwargs) response = post_method(user, 'invitations', data, **kwargs)

@ -9,6 +9,7 @@ from copy import deepcopy
from .utils.config import post_method, patch_method from .utils.config import post_method, patch_method
@pytest.mark.usefixtures("restore")
class TestPostIssues: class TestPostIssues:
def _test_check_response(self, user, data, is_allow, **kwargs): def _test_check_response(self, user, data, is_allow, **kwargs):
response = post_method(user, 'issues', data, **kwargs) response = post_method(user, 'issues', data, **kwargs)
@ -79,6 +80,7 @@ class TestPostIssues:
self._test_check_response(username, data, is_allow, org_id=org) self._test_check_response(username, data, is_allow, org_id=org)
@pytest.mark.usefixtures("restore")
class TestPatchIssues: class TestPatchIssues:
def _test_check_response(self, user, issue_id, data, is_allow, **kwargs): def _test_check_response(self, user, issue_id, data, is_allow, **kwargs):
response = patch_method(user, f'issues/{issue_id}', data, response = patch_method(user, f'issues/{issue_id}', data,

@ -180,7 +180,7 @@ class TestGetAnnotations:
job_id, annotations['job'][str(job_id)], **kwargs) job_id, annotations['job'][str(job_id)], **kwargs)
else: else:
self._test_get_job_annotations_403(username, job_id, **kwargs) self._test_get_job_annotations_403(username, job_id, **kwargs)
@pytest.mark.usefixtures("restore")
class TestPatchJobAnnotations: class TestPatchJobAnnotations:
_ORG = 2 _ORG = 2
@ -259,6 +259,7 @@ class TestPatchJobAnnotations:
self._test_check_respone(is_allow, response, data) self._test_check_respone(is_allow, response, data)
@pytest.mark.usefixtures("restore")
class TestPatchJob: class TestPatchJob:
_ORG = 2 _ORG = 2

@ -42,6 +42,7 @@ class TestGetMemberships:
self._test_cannot_see_memberships(user, org_id=1) self._test_cannot_see_memberships(user, org_id=1)
@pytest.mark.usefixtures("restore")
class TestPatchMemberships: class TestPatchMemberships:
_ORG = 2 _ORG = 2

@ -60,6 +60,7 @@ class TestGetOrganizations:
else: else:
assert response.status_code == HTTPStatus.NOT_FOUND assert response.status_code == HTTPStatus.NOT_FOUND
@pytest.mark.usefixtures("restore")
class TestPatchOrganizations: class TestPatchOrganizations:
_ORG = 2 _ORG = 2
@ -100,6 +101,7 @@ class TestPatchOrganizations:
else: else:
assert response.status_code != HTTPStatus.OK assert response.status_code != HTTPStatus.OK
@pytest.mark.usefixtures("restore")
class TestDeleteOrganizations: class TestDeleteOrganizations:
_ORG = 2 _ORG = 2

@ -110,6 +110,7 @@ class TestGetProjects:
self._test_response_200(user_in_project['username'], project_id, org_id=user_in_project['org']) self._test_response_200(user_in_project['username'], project_id, org_id=user_in_project['org'])
@pytest.mark.usefixtures("restore")
class TestPostProjects: class TestPostProjects:
def _test_create_project_201(self, user, spec, **kwargs): def _test_create_project_201(self, user, spec, **kwargs):
response = post_method(user, '/projects', spec, **kwargs) response = post_method(user, '/projects', spec, **kwargs)

@ -2,8 +2,11 @@
# #
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
from time import sleep
from http import HTTPStatus from http import HTTPStatus
from time import sleep
import pytest
from .utils.config import get_method, post_method from .utils.config import get_method, post_method
@ -26,6 +29,7 @@ def _wait_until_task_is_created(username, task_id):
sleep(1) sleep(1)
@pytest.mark.usefixtures("restore")
class TestGetAnalytics: class TestGetAnalytics:
task_id = 12 task_id = 12
def _test_can_create(self, user, task_id, resources): def _test_can_create(self, user, task_id, resources):

@ -93,6 +93,7 @@ class TestGetTasks:
self._test_assigned_users_to_see_task_data(tasks, users, is_task_staff, org=org['slug']) self._test_assigned_users_to_see_task_data(tasks, users, is_task_staff, org=org['slug'])
@pytest.mark.usefixtures("restore")
class TestPostTasks: class TestPostTasks:
def _test_create_task_201(self, user, spec, **kwargs): def _test_create_task_201(self, user, spec, **kwargs):
response = post_method(user, '/tasks', spec, **kwargs) response = post_method(user, '/tasks', spec, **kwargs)
@ -157,6 +158,7 @@ class TestGetData:
assert response.headers['Content-Type'] == content_type assert response.headers['Content-Type'] == content_type
@pytest.mark.usefixtures("restore")
class TestPatchTaskAnnotations: class TestPatchTaskAnnotations:
def _test_check_respone(self, is_allow, response, data=None): def _test_check_respone(self, is_allow, response, data=None):
if is_allow: if is_allow:

Loading…
Cancel
Save