Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Combine test coverage #3814

Merged
merged 1 commit into from Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .coveragerc
@@ -1,7 +1,7 @@
[run]
cover_pylib = 0
branch = False
source = pulpcore
concurrency = multiprocessing
parallel = true

omit =
/*/tests/*
Expand Down
6 changes: 5 additions & 1 deletion .travis.yml
Expand Up @@ -12,14 +12,18 @@ env:
matrix:
fast_finish: true
addons:
apt:
packages:
- httpie
- jq
# postgres versions provided by el7 RHSCL (lowest supportable version)
postgresql: '9.6'
services:
- postgresql
- redis-server
install: source .travis/install.sh
before_script: source .travis/before_script.sh
script: source .travis/script.sh
script: .travis/script.sh
jobs:
include:
- stage: deploy
Expand Down
5 changes: 0 additions & 5 deletions .travis/before_script.sh
Expand Up @@ -33,8 +33,3 @@ if [ "$TEST" != 'docs' ]; then
fi

pulp-manager reset-admin-password --password admin
pulp-manager runserver >> ~/django_runserver.log 2>&1 &
gunicorn pulpcore.content:server --bind 'localhost:8080' --worker-class 'aiohttp.GunicornWebWorker' -w 2 >> ~/content_app.log 2>&1 &
rq worker -n 'resource_manager@%h' -w 'pulpcore.tasking.worker.PulpWorker' -c 'pulpcore.rqconfig' >> ~/resource_manager.log 2>&1 &
rq worker -n 'reserved_resource_worker_1@%h' -w 'pulpcore.tasking.worker.PulpWorker' -c 'pulpcore.rqconfig' >> ~/reserved_worker-1.log 2>&1 &
sleep 5
55 changes: 40 additions & 15 deletions .travis/script.sh
@@ -1,21 +1,38 @@
#!/usr/bin/env bash
# coding=utf-8

set -veuo pipefail
set -mveuo pipefail

wait_for_pulp() {
TIMEOUT=${1:-5}
while [ "$TIMEOUT" -gt 0 ]
do
echo -n .
sleep 1
TIMEOUT=$(($TIMEOUT - 1))
if [ $(http :8000/pulp/api/v3/status/ | jq '.database_connection.connected and .redis_connection.connected') = 'true' ]
then
echo
return
fi
done
echo
return 1
}

if [ "$TEST" = 'docs' ]; then
pulp-manager runserver >> ~/django_runserver.log 2>&1 &
sleep 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about using wait_for_pulp here too? We've had issues in Travis runs with this exact issue but we never had wait_for_pulp!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is room for improvement: In it's actual state wait_for_pulp checks the availability of the worker threads (and could also check the content app if it were present in the status endpoint). So, it is not usable here unmodified.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK we can leave this as is for now

cd docs
make html
set +euo pipefail
return "$?"
exit
fi


# check the commit message
./.travis/check_commit.sh

# Lint code.
flake8 --config flake8.cfg || exit 1
flake8 --config flake8.cfg

# Run unit tests.
coverage run manage.py test ./pulpcore/tests/unit/
Expand All @@ -29,16 +46,24 @@ show_logs_and_return_non_zero() {
cat ~/reserved_worker-1.log
return "${rc}"
}

# Start services
rq worker -n 'resource_manager@%h' -w 'pulpcore.tasking.worker.PulpWorker' -c 'pulpcore.rqconfig' >> ~/resource_manager.log 2>&1 &
rq worker -n 'reserved_resource_worker_1@%h' -w 'pulpcore.tasking.worker.PulpWorker' -c 'pulpcore.rqconfig' >> ~/reserved_worker-1.log 2>&1 &
gunicorn pulpcore.tests.functional.content_with_coverage:server --bind 'localhost:8080' --worker-class 'aiohttp.GunicornWebWorker' -w 2 >> ~/content_app.log 2>&1 &
pulp-manager runserver --noreload >> ~/django_runserver.log 2>&1 &
wait_for_pulp 20

# Run functional tests
pytest -v -r sx --color=yes --pyargs pulpcore.tests.functional || show_logs_and_return_non_zero
pytest -v -r sx --color=yes --pyargs pulp_file.tests.functional || show_logs_and_return_non_zero
codecov

# Travis' scripts use unbound variables. This is problematic, because the
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, this is only a problem because we used source to call the scripts. Is there any (still valid) reason to do so?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know of a reason.

# changes made to this script's environment appear to persist when Travis'
# scripts execute. Perhaps this script is sourced by Travis? Regardless of why,
# we need to reset the environment when this script finishes.
#
# We can't use `trap cleanup_function EXIT` or similar, because this script is
# apparently sourced, and such a trap won't execute until the (buggy!) calling
# script finishes.
set +euo pipefail
# Stop services to write coverage
kill -SIGINT %?runserver
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. 👍

kill -SIGINT %?content_with_coverage
kill -SIGINT %?reserved_resource_worker
kill -SIGINT %?resource_manager
wait || true

coverage combine
codecov
17 changes: 17 additions & 0 deletions pulpcore/tests/functional/content_with_coverage.py
@@ -0,0 +1,17 @@
import atexit
bmbouter marked this conversation as resolved.
Show resolved Hide resolved
import sys
import coverage

cov = coverage.Coverage()
cov.start()


def finalize_coverage():
print('writing coverage', file=sys.stderr)
cov.stop()
cov.save()


atexit.register(finalize_coverage)

from ...content import server # noqa