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

ci: add coverage to integration tests #410

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .config/nextest.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[profile.default]
slow-timeout = { period = "120s", terminate-after = 1 }
retries = 3 # for flaky tests
retries = 3 # for flaky tests

[profile.integration]
slow-timeout = { period = "3600s", terminate-after = 1 }
31 changes: 13 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,36 +81,31 @@ jobs:
integration-test:
name: Integration Test Suite
runs-on: [self-hosted, linux]
needs: test
needs: rustfmt
steps:
- uses: actions/checkout@v3
- name: Install Clang
run: sudo apt-get update && sudo apt-get install -y clang
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- uses: taiki-e/install-action@cargo-llvm-cov
- uses: taiki-e/install-action@nextest
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- uses: extractions/setup-just@v2
- name: Run integration tests
- name: Run integration tests with coverage
env:
RUST_LOG: warn
run: just run_integration_tests

cli-builds:
name: tycho-cli check
runs-on: [self-hosted, linux]
needs: rustfmt
steps:
- uses: actions/checkout@v3
- name: Install Clang
run: sudo apt-get update && sudo apt-get install -y clang
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
run: just run_integration_tests_cov
- name: Upload integration test coverage to Codecov
uses: codecov/codecov-action@v3
if: github.repository == 'broxus/tycho'
with:
cache-on-failure: true
- uses: extractions/setup-just@v2
- name: Build CLI
run: just build
token: ${{ secrets.CODECOV_TOKEN }}
files: integration_codecov.json
fail_ci_if_error: true

metrics:
name: Metrics
Expand Down
24 changes: 24 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,31 @@ update_rpc_proto:
cargo run -p tycho-gen-protos

# === Integration tests stuff ===
run_integration_tests_cov: prepare_integration_tests
#!/usr/bin/env bash
set -euo pipefail
export INTEGRATION_TEST=1

if [ -n "${CI:-}" ]; then
# Running in CI
RUST_BACKTRACE=1 cargo llvm-cov nextest \
--package tycho-core \
--profile integration \
--cargo-profile release_check \
--test archives heavy_archives \
--run-ignored all \
--output-path integration_codecov.json \
--codecov
else
# Running locally - show coverage report in browser
RUST_BACKTRACE=1 cargo llvm-cov nextest \
--package tycho-core \
--profile integration \
--cargo-profile release_check \
--test archives heavy_archives \
--run-ignored all \
--open
fi
# Runs all tests including ignored. Will take a lot of time to run.
run_integration_tests: prepare_integration_tests
./scripts/run-integration-tests.sh
Expand Down
Empty file modified scripts/common.sh
100644 → 100755
Empty file.
42 changes: 27 additions & 15 deletions scripts/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,42 @@
import os
import sys

def should_collect_coverage(crate_name: str) -> bool:
"""
Determines if coverage should be collected for a crate.

blacklist = ["25519", "tokio"]
Logic:
- In integration tests: only collect for tycho-* crates
- Otherwise: collect for everything except blacklisted crates
"""
# Default blacklist
ALWAYS_BLACKLISTED = {"25519", "tokio"}

# Integration test mode
if os.environ.get("INTEGRATION_TEST"):
return "tycho" in crate_name

# Normal mode
return crate_name not in ALWAYS_BLACKLISTED

def get_crate_name(args):
"""Extract crate name from rustc arguments"""
for i, arg in enumerate(args):
if arg == "--crate-name":
return args[i + 1]
return ""

def main():
# The first argument is the path to rustc, followed by its arguments
args = sys.argv[1:]

# coverage is necessary only for our project
# Get crate name
crate_name = get_crate_name(args)
if any(crate in crate_name for crate in blacklist):

# Check if we should collect coverage
if not should_collect_coverage(crate_name):
try:
# Remove coverage instrumentation flags
instrument_coverage_index = args.index("instrument-coverage")
del args[instrument_coverage_index]
del args[instrument_coverage_index - 1]
Expand All @@ -23,17 +47,5 @@ def main():
# Execute rustc with the potentially modified arguments
os.execvp(args[0], args)


def get_crate_name(args):
for i, arg in enumerate(args):
if arg == "--crate-name":
return args[i + 1]
return ""


def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)


if __name__ == "__main__":
main()
Loading