Skip to content

Commit 561f4e2

Browse files
authored
Reduce number of test cases (cvat-ai#24)
1 parent 391370e commit 561f4e2

File tree

11 files changed

+88
-20
lines changed

11 files changed

+88
-20
lines changed

.github/workflows/main.yml

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v2
19+
1920
- uses: actions/setup-python@v2
2021
with:
2122
python-version: '3.8'
23+
2224
- name: Getting SHA from the default branch
2325
id: get-sha
2426
run: |
@@ -36,6 +38,7 @@ jobs:
3638
3739
echo ::set-output name=default_branch::${DEFAULT_BRANCH}
3840
echo ::set-output name=sha::${SHA}
41+
3942
- name: Waiting a cache creation in the default branch
4043
if: ${{ github.ref_name != 'develop' }}
4144
run: |
@@ -69,13 +72,22 @@ jobs:
6972
echo "Number of attempts expired!"
7073
echo "Probably the creation of the cache is not yet complete. Will continue working without the cache."
7174
fi
75+
7276
- name: Getting CVAT server cache from the default branch
7377
uses: actions/cache@v2
7478
with:
7579
path: /tmp/cvat_cache_server
7680
key: ${{ runner.os }}-build-server-${{ steps.get-sha.outputs.sha }}
81+
82+
- name: Getting CVAT UI cache from the default branch
83+
uses: actions/cache@v2
84+
with:
85+
path: /tmp/cvat_cache_ui
86+
key: ${{ runner.os }}-build-ui-${{ steps.get-sha.outputs.sha }}
87+
7788
- name: Set up Docker Buildx
7889
uses: docker/setup-buildx-action@v1.1.2
90+
7991
- name: Building CVAT server image
8092
uses: docker/build-push-action@v2
8193
with:
@@ -84,11 +96,22 @@ jobs:
8496
cache-from: type=local,src=/tmp/cvat_cache_server
8597
tags: openvino/cvat_server:latest
8698
load: true
99+
100+
- name: Building CVAT UI image
101+
uses: docker/build-push-action@v2
102+
with:
103+
context: .
104+
file: ./Dockerfile.ui
105+
cache-from: type=local,src=/tmp/cvat_cache_ui
106+
tags: openvino/cvat_ui:latest
107+
load: true
108+
87109
- name: Running OPA tests
88110
run: |
89111
curl -L -o opa https://openpolicyagent.org/downloads/v0.34.2/opa_linux_amd64_static
90112
chmod +x ./opa
91113
./opa test cvat/apps/iam/rules
114+
92115
- name: Running REST API tests
93116
env:
94117
API_ABOUT_PAGE: "localhost:8080/api/server/about"
@@ -98,16 +121,22 @@ jobs:
98121
run: |
99122
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
100123
/bin/bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' ${API_ABOUT_PAGE})" != "401" ]]; do sleep 5; done'
124+
101125
pip3 install --user -r tests/rest_api/requirements.txt
102-
pytest tests/rest_api/
126+
pytest tests/rest_api/ -k 'GET'
127+
103128
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
129+
104130
- name: Running unit tests
105131
env:
106132
HOST_COVERAGE_DATA_DIR: ${{ github.workspace }}
107133
CONTAINER_COVERAGE_DATA_DIR: "/coverage_data"
108134
run: |
109-
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}'
110-
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'
135+
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
136+
-c 'coverage run -a manage.py test cvat/apps utils/cli -k 'tasks_id' -k 'lambda' -k 'share' && mv .coverage ${CONTAINER_COVERAGE_DATA_DIR}'
137+
138+
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
139+
-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'
111140
- name: Uploading code coverage results as an artifact
112141
if: github.ref == 'refs/heads/develop'
113142
uses: actions/upload-artifact@v2
@@ -126,9 +155,10 @@ jobs:
126155
strategy:
127156
fail-fast: false
128157
matrix:
129-
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']
158+
specs: ['canvas3d_functionality', 'actions']
130159
steps:
131160
- uses: actions/checkout@v2
161+
132162
- name: Getting SHA from the default branch
133163
id: get-sha
134164
run: |
@@ -146,6 +176,7 @@ jobs:
146176
147177
echo ::set-output name=default_branch::${DEFAULT_BRANCH}
148178
echo ::set-output name=sha::${SHA}
179+
149180
- name: Waiting a cache creation in the default branch
150181
run: |
151182
URL_runs="https://api.github.com/repos/${{ github.repository }}/actions/workflows/cache.yml/runs"
@@ -179,21 +210,26 @@ jobs:
179210
echo "Number of attempts expired!"
180211
echo "Probably the creation of the cache is not yet complete. Will continue working without the cache."
181212
fi
213+
182214
- name: Getting CVAT server cache from the default branch
183215
uses: actions/cache@v2
184216
with:
185217
path: /tmp/cvat_cache_server
186218
key: ${{ runner.os }}-build-server-${{ steps.get-sha.outputs.sha }}
187-
- name: Getting cache CVAT UI from the default branch
219+
220+
- name: Getting CVAT UI cache from the default branch
188221
uses: actions/cache@v2
189222
with:
190223
path: /tmp/cvat_cache_ui
191224
key: ${{ runner.os }}-build-ui-${{ steps.get-sha.outputs.sha }}
225+
192226
- uses: actions/setup-node@v2
193227
with:
194228
node-version: '16.x'
229+
195230
- name: Set up Docker Buildx
196231
uses: docker/setup-buildx-action@v1.1.2
232+
197233
- name: Building CVAT server image
198234
uses: docker/build-push-action@v2
199235
with:
@@ -202,6 +238,7 @@ jobs:
202238
cache-from: type=local,src=/tmp/cvat_cache_server
203239
tags: openvino/cvat_server:latest
204240
load: true
241+
205242
- name: Building CVAT UI image
206243
uses: docker/build-push-action@v2
207244
with:
@@ -210,12 +247,14 @@ jobs:
210247
cache-from: type=local,src=/tmp/cvat_cache_ui
211248
tags: openvino/cvat_ui:latest
212249
load: true
250+
213251
- name: Instrumentation of the code then rebuilding the CVAT UI
214252
if: github.ref == 'refs/heads/develop'
215253
run: |
216254
npm ci
217255
npm run coverage
218256
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f components/serverless/docker-compose.serverless.yml build cvat_ui
257+
219258
- name: Running e2e tests
220259
env:
221260
DJANGO_SU_NAME: 'admin'
@@ -226,38 +265,51 @@ jobs:
226265
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
227266
/bin/bash -c 'while [[ $(curl -s -o /dev/null -w "%{http_code}" ${API_ABOUT_PAGE}) != "401" ]]; do sleep 5; done'
228267
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"
268+
229269
cd ./tests
230270
npm ci
231-
if [[ ${{ github.ref }} == 'refs/heads/develop' ]]; then
232-
if [ ${{ matrix.specs }} == 'canvas3d_functionality' ] || [ ${{ matrix.specs }} == 'canvas3d_functionality_2' ]; then
233-
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'
234-
else
235-
npx cypress run --browser chrome --spec 'cypress/integration/${{ matrix.specs }}/**/*.js,cypress/integration/remove_users_tasks_projects_organizations.js'
236-
fi
237-
mv ./.nyc_output/out.json ./.nyc_output/out_${{ matrix.specs }}.json
271+
272+
if [ ${{ matrix.specs }} == 'canvas3d_functionality' ]; then
273+
# Choosing 5 test files
274+
selected_files=$(find ./cypress/integration | grep -e 'case.*\|issue.*' | grep js | grep 3d | sort | head -5 | tr '\n' ',')
275+
276+
npx cypress run \
277+
--headed \
278+
--browser chrome \
279+
--env coverage=false \
280+
--config-file cypress_canvas3d.json \
281+
--spec "${selected_files} cypress/integration/remove_users_tasks_projects_organizations.js"
238282
else
239-
if [ ${{ matrix.specs }} == 'canvas3d_functionality' ] || [ ${{ matrix.specs }} == 'canvas3d_functionality_2' ]; then
240-
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'
241-
else
242-
npx cypress run --browser chrome --env coverage=false --spec 'cypress/integration/${{ matrix.specs }}/**/*.js,cypress/integration/remove_users_tasks_projects_organizations.js'
243-
fi
283+
# Choosing 20 test files
284+
find ./cypress/integration | grep -e 'case.*\|issue.*' | grep js | sed '/.*3d.*/d' | sort > test_files
285+
selected_files=$({ head -10; tail -10;} < test_files | tr '\n' ',')
286+
rm test_files
287+
288+
npx cypress run \
289+
--browser chrome \
290+
--env coverage=false \
291+
--spec "${selected_files} cypress/integration/remove_users_tasks_projects_organizations.js"
244292
fi
293+
245294
- name: Creating a log file from "cvat" container logs
246295
if: failure()
247296
run: |
248297
docker logs cvat > ${{ github.workspace }}/tests/cvat_${{ matrix.specs }}.log
298+
249299
- name: Uploading cypress screenshots as an artifact
250300
if: failure()
251301
uses: actions/upload-artifact@v2
252302
with:
253303
name: cypress_screenshots_${{ matrix.specs }}
254304
path: ${{ github.workspace }}/tests/cypress/screenshots
305+
255306
- name: Uploading "cvat" container logs as an artifact
256307
if: failure()
257308
uses: actions/upload-artifact@v2
258309
with:
259310
name: cvat_container_logs
260311
path: ${{ github.workspace }}/tests/cvat_${{ matrix.specs }}.log
312+
261313
- name: Uploading code coverage results as an artifact
262314
if: github.ref == 'refs/heads/develop'
263315
uses: actions/upload-artifact@v2

tests/rest_api/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def init_test_db():
3535
_run('docker exec cvat_db psql -U root -d postgres -v from=test_db -v to=cvat -f restore.sql')
3636
_run('docker exec cvat_db dropdb test_db')
3737

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

tests/rest_api/test_cloud_storages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_org_user_get_coud_storage(self, org_id, storage_id, role, is_owner, is_
5959
self._test_cannot_see(username, storage_id, org_id=org_id)
6060

6161

62+
@pytest.mark.usefixtures("restore")
6263
class TestPostCloudStorage:
6364
_SPEC = {
6465
'provider_type': 'AWS_S3_BUCKET',
@@ -120,6 +121,7 @@ def test_org_user_create_coud_storage(self, org_id, role, is_allow, find_users):
120121
else:
121122
self._test_cannot_create(username, self._SPEC, org_id=org_id)
122123

124+
@pytest.mark.usefixtures("restore")
123125
class TestPatchCloudStorage:
124126
_SPEC = {
125127
'display_name': 'New display name',

tests/rest_api/test_invitations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77
from .utils.config import post_method
88

9+
@pytest.mark.usefixtures("restore")
910
class TestCreateInvitations:
1011
def _test_post_invitation_201(self, user, data, invitee, **kwargs):
1112
response = post_method(user, 'invitations', data, **kwargs)

tests/rest_api/test_issues.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from .utils.config import post_method, patch_method
1111

12+
@pytest.mark.usefixtures("restore")
1213
class TestPostIssues:
1314
def _test_check_response(self, user, data, is_allow, **kwargs):
1415
response = post_method(user, 'issues', data, **kwargs)
@@ -79,6 +80,7 @@ def test_member_create_issue(self, org, role, job_staff, is_allow,
7980
self._test_check_response(username, data, is_allow, org_id=org)
8081

8182

83+
@pytest.mark.usefixtures("restore")
8284
class TestPatchIssues:
8385
def _test_check_response(self, user, issue_id, data, is_allow, **kwargs):
8486
response = patch_method(user, f'issues/{issue_id}', data,

tests/rest_api/test_jobs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_non_member_get_job_annotations(self, org, privilege, is_allow,
180180
job_id, annotations['job'][str(job_id)], **kwargs)
181181
else:
182182
self._test_get_job_annotations_403(username, job_id, **kwargs)
183-
183+
@pytest.mark.usefixtures("restore")
184184
class TestPatchJobAnnotations:
185185
_ORG = 2
186186

@@ -259,6 +259,7 @@ def test_user_update_job_annotations(self, org, privilege, job_staff, is_allow,
259259

260260
self._test_check_respone(is_allow, response, data)
261261

262+
@pytest.mark.usefixtures("restore")
262263
class TestPatchJob:
263264
_ORG = 2
264265

tests/rest_api/test_memberships.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def test_non_members_cannot_see_members_membership(self):
4242
self._test_cannot_see_memberships(user, org_id=1)
4343

4444

45+
@pytest.mark.usefixtures("restore")
4546
class TestPatchMemberships:
4647
_ORG = 2
4748

tests/rest_api/test_organizations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def test_can_see_specific_organization(self, privilege, role, is_member,
6060
else:
6161
assert response.status_code == HTTPStatus.NOT_FOUND
6262

63+
@pytest.mark.usefixtures("restore")
6364
class TestPatchOrganizations:
6465
_ORG = 2
6566

@@ -100,6 +101,7 @@ def test_can_update_specific_organization(self, privilege, role, is_member,
100101
else:
101102
assert response.status_code != HTTPStatus.OK
102103

104+
@pytest.mark.usefixtures("restore")
103105
class TestDeleteOrganizations:
104106
_ORG = 2
105107

tests/rest_api/test_projects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def test_if_org_member_supervisor_or_worker_can_see_project(self, projects,
110110

111111
self._test_response_200(user_in_project['username'], project_id, org_id=user_in_project['org'])
112112

113+
@pytest.mark.usefixtures("restore")
113114
class TestPostProjects:
114115
def _test_create_project_201(self, user, spec, **kwargs):
115116
response = post_method(user, '/projects', spec, **kwargs)

tests/rest_api/test_remote_url.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
from time import sleep
65
from http import HTTPStatus
6+
from time import sleep
7+
8+
import pytest
9+
710
from .utils.config import get_method, post_method
811

912

@@ -26,6 +29,7 @@ def _wait_until_task_is_created(username, task_id):
2629
sleep(1)
2730

2831

32+
@pytest.mark.usefixtures("restore")
2933
class TestGetAnalytics:
3034
task_id = 12
3135
def _test_can_create(self, user, task_id, resources):

0 commit comments

Comments
 (0)