Skip to content
Snippets Groups Projects
Commit 21dc91c4 authored by Colton Leekley-Winslow's avatar Colton Leekley-Winslow
Browse files

Record coverage for integration tests

parent f52d13c8
No related branches found
No related tags found
No related merge requests found
import atexit
import json import json
import os
import sys import sys
import traceback import traceback
...@@ -225,7 +227,8 @@ def app_factory(*_, **__): ...@@ -225,7 +227,8 @@ def app_factory(*_, **__):
application = webapp2.WSGIApplication(routes, debug=config.__config['core']['debug']) application = webapp2.WSGIApplication(routes, debug=config.__config['core']['debug'])
application.router.set_dispatcher(dispatcher) application.router.set_dispatcher(dispatcher)
application.request_class = SciTranRequest application.request_class = SciTranRequest
if os.environ.get("SCITRAN_RUNTIME_COVERAGE") == "true":
start_coverage()
# configure new relic # configure new relic
if config.__config['core']['newrelic']: if config.__config['core']['newrelic']:
try: try:
...@@ -241,3 +244,16 @@ def app_factory(*_, **__): ...@@ -241,3 +244,16 @@ def app_factory(*_, **__):
sys.exit(1) sys.exit(1)
return application return application
# Functions to enable code coverage when API is started for testing
def start_coverage():
import coverage
config.log.info("Enabling code coverage")
cov = coverage.coverage(source=["api"], data_suffix="integration-tests")
cov.start()
atexit.register(save_coverage, cov)
def save_coverage(cov):
config.log.info("Saving coverage")
cov.stop()
cov.save()
# vim: filetype=python # vim: filetype=python
import sys
import os.path
from api import api from api import api
application = api.app_factory() application = api.app_factory()
...@@ -76,6 +76,7 @@ SCITRAN_RUNTIME_PORT=${SCITRAN_RUNTIME_PORT:-"8080"} ...@@ -76,6 +76,7 @@ SCITRAN_RUNTIME_PORT=${SCITRAN_RUNTIME_PORT:-"8080"}
SCITRAN_RUNTIME_UWSGI_INI=${SCITRAN_RUNTIME_UWSGI_INI:-""} SCITRAN_RUNTIME_UWSGI_INI=${SCITRAN_RUNTIME_UWSGI_INI:-""}
SCITRAN_RUNTIME_BOOTSTRAP=${SCITRAN_RUNTIME_BOOTSTRAP:-"./bootstrap.json"} SCITRAN_RUNTIME_BOOTSTRAP=${SCITRAN_RUNTIME_BOOTSTRAP:-"./bootstrap.json"}
SCITRAN_RUNTIME_SSL_PEM=${SCITRAN_RUNTIME_SSL_PEM:-""} SCITRAN_RUNTIME_SSL_PEM=${SCITRAN_RUNTIME_SSL_PEM:-""}
SCITRAN_RUNTIME_COVERAGE=${SCITRAN_RUNTIME_COVERAGE:-"false"}
SCITRAN_CORE_DRONE_SECRET=${SCITRAN_CORE_DRONE_SECRET:-$( openssl rand -base64 32 )} SCITRAN_CORE_DRONE_SECRET=${SCITRAN_CORE_DRONE_SECRET:-$( openssl rand -base64 32 )}
...@@ -106,7 +107,7 @@ clean_up () { ...@@ -106,7 +107,7 @@ clean_up () {
kill $MONGOD_PID || true kill $MONGOD_PID || true
kill $UWSGI_PID || true kill $UWSGI_PID || true
deactivate || true deactivate || true
wait wait 2> /dev/null
} }
trap clean_up EXIT trap clean_up EXIT
......
...@@ -4,6 +4,8 @@ set -eu ...@@ -4,6 +4,8 @@ set -eu
unset CDPATH unset CDPATH
cd "$( dirname "${BASH_SOURCE[0]}" )/../.." cd "$( dirname "${BASH_SOURCE[0]}" )/../.."
rm -f .coverage.integration-tests
USAGE=" USAGE="
Usage:\n Usage:\n
$0 <api-base-url> <mongodb-uri>\n $0 <api-base-url> <mongodb-uri>\n
...@@ -40,7 +42,7 @@ rm -rf test/integration_tests/python/__pycache__ ...@@ -40,7 +42,7 @@ rm -rf test/integration_tests/python/__pycache__
BASE_URL="$SCITRAN_SITE_API_URL" \ BASE_URL="$SCITRAN_SITE_API_URL" \
MONGO_PATH="$MONGODB_URI" \ MONGO_PATH="$MONGODB_URI" \
py.test --cov=api --cov-append test/integration_tests/python py.test test/integration_tests/python
newman run test/integration_tests/postman/integration_tests.postman_collection -e test/integration_tests/postman/environments/integration_tests.postman_environment newman run test/integration_tests/postman/integration_tests.postman_collection -e test/integration_tests/postman/environments/integration_tests.postman_environment
......
...@@ -13,7 +13,13 @@ SCITRAN_PERSISTENT_PATH="$( mktemp -d )" ...@@ -13,7 +13,13 @@ SCITRAN_PERSISTENT_PATH="$( mktemp -d )"
clean_up () { clean_up () {
kill $API_PID || true kill $API_PID || true
wait 2> /dev/null
rm -rf "$SCITRAN_PERSISTENT_PATH" rm -rf "$SCITRAN_PERSISTENT_PATH"
# Report on unit tests and integration tests separately
coverage report -m
rm .coverage
coverage combine
coverage report -m
} }
trap clean_up EXIT trap clean_up EXIT
...@@ -29,6 +35,7 @@ trap clean_up EXIT ...@@ -29,6 +35,7 @@ trap clean_up EXIT
SCITRAN_RUNTIME_PORT=8081 \ SCITRAN_RUNTIME_PORT=8081 \
SCITRAN_CORE_DRONE_SECRET=integration-tests \ SCITRAN_CORE_DRONE_SECRET=integration-tests \
SCITRAN_RUNTIME_COVERAGE="true" \
./bin/run-dev-osx.sh -T -U -I & ./bin/run-dev-osx.sh -T -U -I &
API_PID=$! API_PID=$!
......
...@@ -8,6 +8,19 @@ cd "$( dirname "${BASH_SOURCE[0]}" )/../.." ...@@ -8,6 +8,19 @@ cd "$( dirname "${BASH_SOURCE[0]}" )/../.."
./test/bin/run-unit-tests.sh ./test/bin/run-unit-tests.sh
clean_up () {
kill $API_PID || true
wait 2> /dev/null
# Report on unit tests and integration tests separately
# Only submit integration test coverage to coveralls
coverage report -m
rm .coverage
coverage combine
coverage report -m
}
trap clean_up EXIT
API_BASE_URL="http://localhost:8081/api" API_BASE_URL="http://localhost:8081/api"
SCITRAN_PERSISTENT_DB_PORT=${SCITRAN_PERSISTENT_DB_PORT:-"9001"} SCITRAN_PERSISTENT_DB_PORT=${SCITRAN_PERSISTENT_DB_PORT:-"9001"}
SCITRAN_PERSISTENT_DB_URI=${SCITRAN_PERSISTENT_DB_URI:-"mongodb://localhost:$SCITRAN_PERSISTENT_DB_PORT/scitran"} SCITRAN_PERSISTENT_DB_URI=${SCITRAN_PERSISTENT_DB_URI:-"mongodb://localhost:$SCITRAN_PERSISTENT_DB_PORT/scitran"}
...@@ -23,7 +36,9 @@ uwsgi --http "localhost:8081" --master --http-keepalive \ ...@@ -23,7 +36,9 @@ uwsgi --http "localhost:8081" --master --http-keepalive \
--logformat '%(addr) - %(user) [%(ltime)] "%(method) %(uri) %(proto)" %(status) %(size) "%(referer)" "%(uagent)" request_id=%(request_id)' \ --logformat '%(addr) - %(user) [%(ltime)] "%(method) %(uri) %(proto)" %(status) %(size) "%(referer)" "%(uagent)" request_id=%(request_id)' \
--env "SCITRAN_PERSISTENT_DB_URI=$SCITRAN_PERSISTENT_DB_URI" \ --env "SCITRAN_PERSISTENT_DB_URI=$SCITRAN_PERSISTENT_DB_URI" \
--env "SCITRAN_PERSISTENT_PATH=$SCITRAN_PERSISTENT_PATH" \ --env "SCITRAN_PERSISTENT_PATH=$SCITRAN_PERSISTENT_PATH" \
--env "SCITRAN_PERSISTENT_DATA_PATH=$SCITRAN_PERSISTENT_DATA_PATH" & --env "SCITRAN_PERSISTENT_DATA_PATH=$SCITRAN_PERSISTENT_DATA_PATH" \
--env 'SCITRAN_RUNTIME_COVERAGE=true' &
API_PID=$!
./test/bin/run-integration-tests.sh \ ./test/bin/run-integration-tests.sh \
"$API_BASE_URL" \ "$API_BASE_URL" \
......
...@@ -16,4 +16,6 @@ echo "Checking for files with windows style newline:" ...@@ -16,4 +16,6 @@ echo "Checking for files with windows style newline:"
# Which have a mismatched __file__ attribute when loaded in docker container # Which have a mismatched __file__ attribute when loaded in docker container
rm -rf test/unit_tests/python/__pycache__ rm -rf test/unit_tests/python/__pycache__
PYTHONPATH="$( pwd )" py.test --cov=api --cov-append test/unit_tests/python rm -f .coverage
PYTHONPATH="$( pwd )" py.test --cov=api test/unit_tests/python
coverage==4.0.3 coverage==4.0.3
coveralls==1.1 coveralls==1.1
pylint==1.5.3 pylint==1.5.3
pymongo==3.2
pytest-cov==2.2.0 pytest-cov==2.2.0
pytest-watch==3.8.0 pytest-watch==3.8.0
pytest==2.8.5 pytest==2.8.5
python-dateutil==1.5
requests==2.9.1
mock==2.0.0 mock==2.0.0
testfixtures==4.10.1 testfixtures==4.10.1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment