Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage fixes #6420

Merged
merged 13 commits into from
Jul 10, 2023
8 changes: 7 additions & 1 deletion .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ codecov:
require_ci_to_pass: yes
notify:
wait_for_ci: yes
after_n_builds: 16

coverage:
status:
patch: false
project:
default:
target: auto
threshold: 5%
32 changes: 5 additions & 27 deletions .github/workflows/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,12 @@ jobs:
- name: CVAT server. Build and push
uses: docker/build-push-action@v3
with:
build-args: |
"COVERAGE_PROCESS_START=.coveragerc"
cache-from: type=local,src=/tmp/cvat_cache_server
context: .
file: Dockerfile
tags: cvat/server
outputs: type=docker,dest=/tmp/cvat_server/image.tar

- name: Instrumentation of the code then rebuilding the CVAT UI
run: |
yarn --frozen-lockfile
yarn run coverage

- name: CVAT UI. Build and push
uses: docker/build-push-action@v3
with:
Expand Down Expand Up @@ -161,8 +154,6 @@ jobs:

- name: Running REST API and SDK tests
id: run_tests
env:
COVERAGE_PROCESS_START: ".coveragerc"
run: |
pip3 install -r cvat-sdk/gen/requirements.txt
./cvat-sdk/gen/generate.sh
Expand All @@ -171,12 +162,7 @@ jobs:
pip3 install -e ./cvat-sdk
pip3 install -e ./cvat-cli

pytest tests/python/ --cov --cov-report xml

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
pytest tests/python/

- name: Creating a log file from cvat containers
if: failure() && steps.run_tests.conclusion == 'failure'
Expand Down Expand Up @@ -236,15 +222,10 @@ jobs:
while [[ $(curl -s -o /dev/null -w "%{http_code}" localhost:8181/health?bundles) != "200" && max_tries -gt 0 ]]; do (( max_tries-- )); sleep 5; done

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 && coverage json && mv coverage.json ${CONTAINER_COVERAGE_DATA_DIR}'
-c 'python manage.py test cvat/apps -v 2'

docker compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
-c 'yarn --frozen-lockfile --ignore-scripts && yarn workspace cvat-core run test && mv cvat-core/reports/coverage/coverage-final.json ${CONTAINER_COVERAGE_DATA_DIR}'

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
-c 'yarn --frozen-lockfile --ignore-scripts && yarn workspace cvat-core run test'

- name: Creating a log file from cvat containers
if: failure()
Expand Down Expand Up @@ -340,19 +321,16 @@ jobs:
npx cypress run \
--headed \
--browser chrome \
--env coverage=false \
--config-file cypress_canvas3d.config.js \
--spec 'cypress/e2e/${{ matrix.specs }}/**/*.js,cypress/e2e/remove_users_tasks_projects_organizations.js'
else
npx cypress run \
--browser chrome \
--env coverage=false \
--spec 'cypress/e2e/${{ matrix.specs }}/**/*.js,cypress/e2e/remove_users_tasks_projects_organizations.js'
fi

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Creating a log file from "cvat" container logs
if: failure()
run: |
Expand Down
46 changes: 35 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ jobs:
env:
COVERAGE_PROCESS_START: ".coveragerc"
run: |
pytest tests/python/ --cov --cov-report xml
pytest tests/python/ --cov --cov-report=json

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
- name: Uploading code coverage results as an artifact
uses: actions/upload-artifact@v3.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: coverage_results
path: |
coverage*.json

- name: Creating a log file from cvat containers
if: failure() && steps.run_tests.conclusion == 'failure'
Expand Down Expand Up @@ -230,15 +232,18 @@ jobs:
while [[ $(curl -s -o /dev/null -w "%{http_code}" localhost:8181/health?bundles) != "200" && max_tries -gt 0 ]]; do (( max_tries-- )); sleep 5; done

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 && coverage json && mv coverage.json ${CONTAINER_COVERAGE_DATA_DIR}'
-c 'coverage run -a manage.py test cvat/apps && coverage json && mv coverage.json ${CONTAINER_COVERAGE_DATA_DIR}/unit_tests_coverage.json'

docker compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
-c 'yarn --frozen-lockfile --ignore-scripts && yarn workspace cvat-core run test && mv cvat-core/reports/coverage/coverage-final.json ${CONTAINER_COVERAGE_DATA_DIR}'

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
- name: Uploading code coverage results as an artifact
uses: actions/upload-artifact@v3.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: coverage_results
path: |
${{ github.workspace }}/coverage-final.json
${{ github.workspace }}/unit_tests_coverage.json

- name: Creating a log file from cvat containers
if: failure()
Expand Down Expand Up @@ -339,11 +344,14 @@ jobs:
--browser chrome \
--spec 'cypress/e2e/${{ matrix.specs }}/**/*.js,cypress/e2e/remove_users_tasks_projects_organizations.js'
fi
mv coverage/coverage-final.json coverage/${{ matrix.specs }}_coverage.json

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
- name: Uploading code coverage results as an artifact
uses: actions/upload-artifact@v3.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: coverage_results
path: |
tests/coverage/${{ matrix.specs }}_coverage.json

- name: Creating a log file from "cvat" container logs
if: failure()
Expand Down Expand Up @@ -463,3 +471,19 @@ jobs:

docker tag cvat/ui:latest "${UI_IMAGE_REPO}:dev"
docker push "${UI_IMAGE_REPO}:dev"

codecov:
runs-on: ubuntu-latest
needs: [unit_testing, e2e_testing, rest_api_testing]
steps:
- uses: actions/checkout@v3

- name: Downloading coverage results
uses: actions/download-artifact@v3
with:
name: coverage_results

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
27 changes: 5 additions & 22 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,13 @@ jobs:
- name: CVAT server. Build and push
uses: docker/build-push-action@v3
with:
build-args: |
"COVERAGE_PROCESS_START=.coveragerc"
cache-from: type=local,src=/tmp/cvat_cache_server
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta-server.outputs.tags }}
labels: ${{ steps.meta-server.outputs.labels }}

- name: Instrumentation of the code then rebuilding the CVAT UI
run: |
yarn --frozen-lockfile
yarn run coverage

- name: CVAT UI. Build and push
uses: docker/build-push-action@v3
with:
Expand Down Expand Up @@ -165,8 +158,6 @@ jobs:
./opa test cvat/apps/iam/rules

- name: REST API and SDK tests
env:
COVERAGE_PROCESS_START: ".coveragerc"
run: |
pip3 install -r cvat-sdk/gen/requirements.txt
./cvat-sdk/gen/generate.sh
Expand All @@ -175,7 +166,7 @@ jobs:
pip3 install -e ./cvat-sdk
pip3 install -e ./cvat-cli

pytest tests/python/ --cov --cov-report xml
pytest tests/python/
pytest tests/python/ --stop-services

- name: Unit tests
Expand All @@ -188,18 +179,13 @@ jobs:
while [[ $(curl -s -o /dev/null -w "%{http_code}" localhost:8181/health?bundles) != "200" && max_tries -gt 0 ]]; do (( max_tries-- )); sleep 5; done

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 && coverage json && mv coverage.json ${CONTAINER_COVERAGE_DATA_DIR}'
-c 'python manage.py test cvat/apps -v 2'

docker compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
-c 'yarn --frozen-lockfile --ignore-scripts && yarn workspace cvat-core run test && mv cvat-core/reports/coverage/coverage-final.json ${CONTAINER_COVERAGE_DATA_DIR}'
-c 'yarn --frozen-lockfile --ignore-scripts && yarn workspace cvat-core run test'

docker compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml down -v

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}

e2e_testing:
needs: build
runs-on: ubuntu-latest
Expand Down Expand Up @@ -304,19 +290,16 @@ jobs:
npx cypress run \
--headed \
--browser chrome \
--env coverage=false \
--config-file cypress_canvas3d.config.js \
--spec 'cypress/e2e/${{ matrix.specs }}/**/*.js,cypress/e2e/remove_users_tasks_projects_organizations.js'
else
npx cypress run \
--browser chrome \
--env coverage=false \
--spec 'cypress/e2e/${{ matrix.specs }}/**/*.js,cypress/e2e/remove_users_tasks_projects_organizations.js'
fi

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Creating a log file from "cvat" container logs
if: failure()
run: |
Expand Down
10 changes: 6 additions & 4 deletions cvat/rqworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ def execute_job(self, *args, **kwargs):

if os.environ.get("COVERAGE_PROCESS_START"):
import coverage
default_exit = os._exit

def coverage_exit():
def coverage_exit(*args, **kwargs):
cov = coverage.Coverage.current()
cov.stop()
cov.save()
os._exit(0)
if cov:
cov.stop()
cov.save()
default_exit(*args, **kwargs)

os._exit = coverage_exit
2 changes: 1 addition & 1 deletion tests/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pytest==6.2.5
pytest-cases==3.6.13
pytest-timeout==2.1.0
pytest-cov==4.0.0
pytest-cov==4.1.0
sizov-kirill marked this conversation as resolved.
Show resolved Hide resolved
requests==2.31.0
deepdiff==5.6.0
boto3==1.17.61
Expand Down
1 change: 1 addition & 0 deletions tests/python/rest_api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,6 +2279,7 @@ def _init_tasks(cls):

cls.data[key] = (task, dataset_file)

@pytest.mark.skip("Fails sometimes, needs to be fixed")
sizov-kirill marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.parametrize(
"task_kind, annotation_kind, expect_success",
[
Expand Down
6 changes: 3 additions & 3 deletions tests/python/shared/fixtures/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ def collect_code_coverage_from_containers():

# get code coverage report
docker_exec(container, "coverage combine", capture_output=False)
docker_exec(container, "coverage xml", capture_output=False)
docker_exec(container, "coverage json", capture_output=False)
docker_cp(
f"{PREFIX}_{container}_1:home/django/coverage.xml",
f"coverage_{container}.xml",
f"{PREFIX}_{container}_1:home/django/coverage.json",
f"coverage_{container}.json",
)


Expand Down