feat_: integration tests coverage

This commit is contained in:
Igor Sirotin 2024-09-05 18:39:56 +01:00
parent b2a4f100f9
commit edffaae9f3
No known key found for this signature in database
GPG Key ID: 425E227CAAB81F95
7 changed files with 103 additions and 23 deletions

2
.gitignore vendored
View File

@ -108,3 +108,5 @@ __pycache__/
.pytest_cache/ .pytest_cache/
.envrc .envrc
report/results.xml report/results.xml
integration-tests/coverage
integration-tests/reports

View File

@ -488,14 +488,11 @@ test-verif-proxy-wrapper:
CGO_CFLAGS="$(CGO_CFLAGS)" go test -v github.com/status-im/status-go/rpc -tags gowaku_skip_migrations,nimbus_light_client -run ^TestProxySuite$$ -testify.m TestRun -ldflags $(LDFLAGS) CGO_CFLAGS="$(CGO_CFLAGS)" go test -v github.com/status-im/status-go/rpc -tags gowaku_skip_migrations,nimbus_light_client -run ^TestProxySuite$$ -testify.m TestRun -ldflags $(LDFLAGS)
run-integration-tests: SHELL := /bin/sh #run-integration-tests: SHELL := /bin/sh # Run not in nix-shell, we need codecov
run-integration-tests: export INTEGRATION_TESTS_DOCKER_UID ?= $(shell id -u $$USER) run-integration-tests: export INTEGRATION_TESTS_DOCKER_UID ?= $(call sh, id -u $$USER)
run-integration-tests: export INTEGRATION_TESTS_REPORT_CODECOV = false
run-integration-tests: run-integration-tests:
docker-compose -f integration-tests/docker-compose.anvil.yml -f integration-tests/docker-compose.test.status-go.yml up -d --build --remove-orphans; \ @./_assets/scripts/run_integration_tests.sh
docker-compose -f integration-tests/docker-compose.anvil.yml -f integration-tests/docker-compose.test.status-go.yml logs -f tests-rpc; \
exit_code=$$(docker inspect integration-tests_tests-rpc_1 -f '{{.State.ExitCode}}'); \
docker-compose -f integration-tests/docker-compose.anvil.yml -f integration-tests/docker-compose.test.status-go.yml down; \
exit $$exit_code
run-anvil: SHELL := /bin/sh run-anvil: SHELL := /bin/sh
run-anvil: run-anvil:

View File

@ -42,11 +42,11 @@ pipeline {
always { always {
script { script {
archiveArtifacts( archiveArtifacts(
artifacts: '**/results.xml', artifacts: 'reports/*.xml',
allowEmptyArchive: true, allowEmptyArchive: true,
) )
junit( junit(
testResults: '**/results.xml', testResults: 'reports/*.xml',
skipOldReports: true, skipOldReports: true,
skipPublishingChecks: true, skipPublishingChecks: true,
skipMarkingBuildUnstable: true, skipMarkingBuildUnstable: true,

21
_assets/scripts/codecov.sh Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
source "${GIT_ROOT}/_assets/scripts/colors.sh"
report_to_codecov() {
# https://docs.codeclimate.com/docs/jenkins#jenkins-ci-builds
echo -e "${GRN}Uploading coverage report to Codecov${RST}"
local tests_report_wildcard="${1}"
local coverage_report="${2}"
local test_type="${3}"
# Gather report files with given wildcard
local report_files_args=""
for file in ${tests_report_wildcard}; do
report_files_args+="--file ${file} "
done
codecov do-upload --token "${CODECOV_TOKEN}" --report-type test_results ${report_files_args}
codecov upload-process --token "${CODECOV_TOKEN}" -f ${coverage_report} -F "${test_type}"
}

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bash
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
source "${GIT_ROOT}/_assets/scripts/colors.sh"
source "${GIT_ROOT}/_assets/scripts/codecov.sh"
echo -e "${GRN}Running integration tests${RST}, HEAD: $(git rev-parse HEAD)"
root_path=./integration-tests
coverage_reports_path="${root_path}/coverage"
# Cleanup any previous coverage reports
rm -rf ${coverage_reports_path}
# Run integration tests
docker-compose \
-f ${root_path}/docker-compose.anvil.yml \
-f ${root_path}/docker-compose.test.status-go.yml \
up -d --build --remove-orphans;
# Save logs
docker-compose \
-f ${root_path}/docker-compose.anvil.yml \
-f ${root_path}/docker-compose.test.status-go.yml \
logs -f tests-rpc;
# Retrieve exit code
exit_code=$(docker inspect integration-tests_tests-rpc_1 -f '{{.State.ExitCode}}');
# Stop and remove containers
docker-compose \
-f ${root_path}/docker-compose.anvil.yml \
-f ${root_path}/docker-compose.test.status-go.yml \
down;
# Early exit if tests failed
if [[ "$exit_code" -ne 0 ]]; then
exit $exit_code
fi
# Report to Codecov
if [[ ${INTEGRATION_TESTS_REPORT_CODECOV} == 'true' ]]; then
# Docs: https://go.dev/blog/integration-test-coverage
binary_coverage_reports_path="${coverage_reports_path}/binary"
merged_coverage_reports_path="${coverage_reports_path}/merged"
full_coverage_profile="${coverage_reports_path}/coverage.out"
test_results_path="${root_path}/reports"
# Clean merged reports directory
mkdir -p ${merged_coverage_reports_path}
# Merge coverage reports
go tool covdata merge -i=${binary_coverage_reports_path} -o=${merged_coverage_reports_path}
# Convert coverage reports to profile
go tool covdata textfmt -i=${merged_coverage_reports_path} -o=${full_coverage_profile}
# Upload reports to Codecov
report_to_codecov "${test_results_path}/*.xml" "${full_coverage_profile}" "integration"
fi

View File

@ -2,8 +2,8 @@
set -o pipefail set -o pipefail
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel) GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
source "${GIT_ROOT}/_assets/scripts/colors.sh" source "${GIT_ROOT}/_assets/scripts/colors.sh"
source "${GIT_ROOT}/_assets/scripts/codecov.sh"
if [[ $UNIT_TEST_RERUN_FAILS == 'true' ]]; then if [[ $UNIT_TEST_RERUN_FAILS == 'true' ]]; then
GOTESTSUM_EXTRAFLAGS="${GOTESTSUM_EXTRAFLAGS} --rerun-fails" GOTESTSUM_EXTRAFLAGS="${GOTESTSUM_EXTRAFLAGS} --rerun-fails"
@ -162,14 +162,7 @@ if [[ $UNIT_TEST_REPORT_CODECLIMATE == 'true' ]]; then
fi fi
if [[ $UNIT_TEST_REPORT_CODECOV == 'true' ]]; then if [[ $UNIT_TEST_REPORT_CODECOV == 'true' ]]; then
echo -e "${GRN}Uploading coverage report to Codecov${RST}" report_to_codecov "report_*.xml" ${final_coverage_report} "unit"
# https://docs.codeclimate.com/docs/jenkins#jenkins-ci-builds
codecov_report_files_args=""
for file in report_*.xml; do
codecov_report_files_args+="--file ${file} "
done
codecov do-upload --token "${CODECOV_TOKEN}" --report-type test_results ${codecov_report_files_args}
codecov --token "${CODECOV_TOKEN}" -f ${final_coverage_report} -F "unit"
fi fi
# Generate report with test stats # Generate report with test stats

View File

@ -16,10 +16,11 @@ services:
timeout: 2s timeout: 2s
retries: 120 retries: 120
environment: environment:
GOCOVERDIR: "./coverage/integration" GOCOVERDIR: "./coverage/binary"
volumes: volumes:
- ./coverage:./coverage/integration - ./coverage:/coverage
# TODO: Remove this duplication when implemented: https://github.com/status-im/status-go/issues/5803
status-go-no-funds: status-go-no-funds:
build: build:
context: ../ context: ../
@ -37,9 +38,9 @@ services:
timeout: 2s timeout: 2s
retries: 120 retries: 120
environment: environment:
GOCOVERDIR: "./coverage/integration" GOCOVERDIR: "/coverage/binary"
volumes: volumes:
- ./coverage:./coverage/integration - ./coverage:/coverage
tests-rpc: tests-rpc:
user: ${INTEGRATION_TESTS_DOCKER_UID} user: ${INTEGRATION_TESTS_DOCKER_UID}
@ -53,6 +54,12 @@ services:
build: build:
context: . context: .
dockerfile: Dockerfile.tests-rpc dockerfile: Dockerfile.tests-rpc
entrypoint: ["pytest", "-m", "wallet", "--rpc_url=http://status-go:3333", "--rpc_url_2=http://status-go-no-funds:3333"] entrypoint: [
"pytest",
"-m", "wallet",
"--rpc_url=http://status-go:3333",
"--rpc_url_2=http://status-go-no-funds:3333",
"--junitxml=/tests-rpc/reports/report.xml",
]
volumes: volumes:
- .:/tests-rpc - .:/tests-rpc