Skip to content

Commit

Permalink
tracing: add static level tests for spans and instrumented fns (#1872)
Browse files Browse the repository at this point in the history
The current tests for the compile-time maximum level were not being run
in `--release` mode, and did not previously assert anything about
`Span`s.

This also adds some test cases for various `#[instrument]`-ed functions.
  • Loading branch information
Swatinem authored and hawkw committed Feb 3, 2022
1 parent f5ad56a commit 4a044d4
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 101 deletions.
89 changes: 0 additions & 89 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,56 +127,6 @@ jobs:
working-directory: ${{ matrix.subcrate }}
run: cargo hack check --feature-powerset --no-dev-deps

cargo-check-tracing:
runs-on: ubuntu-latest
strategy:
matrix:
featureset:
- ""
- async-await
- async-await std
- async-await log-always
- async-await std log-always
- log-always
- std log-always
- std
fail-fast: false
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: cargo check
working-directory: tracing
run: cargo check --no-default-features --features "${{ matrix.featureset }}"

cargo-check-subscriber:
runs-on: ubuntu-latest
strategy:
matrix:
featureset:
- ""
- fmt
- fmt ansi
- fmt json
- fmt json ansi
- fmt registry
- fmt env-filter
- registry
- env-filter
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: cargo check
working-directory: tracing-subscriber
run: cargo check --no-default-features --features "${{ matrix.featureset }}"

test-versions:
# Test against the stable, beta, and nightly Rust toolchains on ubuntu-latest.
needs: check
Expand Down Expand Up @@ -289,45 +239,6 @@ jobs:
command: test
args: --all --features "valuable"


features-stable:
# Feature flag tests that run on stable Rust.
# TODO(david): once tracing's MSRV goes up to Rust 1.51, we should be able to switch to
# using cargo's V2 feature resolver (https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions)
# and avoid cd'ing into each crate's directory.
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: "Test log support"
run: cargo test
working-directory: "tracing/test-log-support"
- name: "Test static max level"
run: cargo test
working-directory: "tracing/test_static_max_level_features"
- name: "Test tracing-core no-std support"
run: cargo test --no-default-features
working-directory: tracing-core
- name: "Test tracing no-std support"
run: cargo test --lib --tests --no-default-features
working-directory: tracing
# this skips running doctests under the `--no-default-features` flag,
# as rustdoc isn't aware of cargo's feature flags.
- name: "Test tracing-subscriber no-std support"
run: cargo test --lib --tests --no-default-features
working-directory: tracing-subscriber
- name: "Test tracing-subscriber with liballoc only"
run: cargo test --lib --tests --no-default-features --features "alloc"
working-directory: tracing-subscriber
- name: "Test tracing-subscriber with no default features"
run: cargo test --lib --tests --no-default-features --features "std"
working-directory: tracing-subscriber

style:
# Check style.
needs: check
Expand Down
147 changes: 147 additions & 0 deletions .github/workflows/check_features.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
name: Check Features

on:
push:
branches:
- master
- "v0.1.x"
pull_request: {}

env:
# Disable incremental compilation.
#
# Incremental compilation is useful as part of an edit-build-test-edit cycle,
# as it lets the compiler avoid recompiling code that hasn't changed. However,
# on CI, we're not making small edits; we're almost always building the entire
# project from scratch. Thus, incremental compilation on CI actually
# introduces *additional* overhead to support making future builds
# faster...but no future builds will ever occur in any given CI environment.
#
# See https://matklad.github.io/2021/09/04/fast-rust-builds.html#ci-workflow
# for details.
CARGO_INCREMENTAL: 0
# Allow more retries for network requests in cargo (downloading crates) and
# rustup (installing toolchains). This should help to reduce flaky CI failures
# from transient network timeouts or other issues.
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
# Don't emit giant backtraces in the CI logs.
RUST_BACKTRACE: short

jobs:
cargo-hack:
runs-on: ubuntu-latest
strategy:
matrix:
# cargo hack --feature-powerset will have a significant permutation
# number, we can't just use --all as it increases the runtime
# further than what we would like to
subcrate:
- tracing-attributes
- tracing-core
- tracing-futures
- tracing-log
- tracing-macros
- tracing-serde
- tracing-tower
# tracing and tracing-subscriber have too many features to be checked by
# cargo-hack --feature-powerset, combinatorics there is exploding.
#- tracing
#- tracing-subscriber
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Install cargo-hack
run: |
curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xzf - -C ~/.cargo/bin
- name: cargo hack check
working-directory: ${{ matrix.subcrate }}
run: cargo hack check --feature-powerset --no-dev-deps

cargo-check-tracing:
runs-on: ubuntu-latest
strategy:
matrix:
featureset:
- ""
- log-always
- std log-always
- std
fail-fast: false
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: cargo check
working-directory: tracing
run: cargo check --no-default-features --features "${{ matrix.featureset }}"

cargo-check-subscriber:
runs-on: ubuntu-latest
strategy:
matrix:
featureset:
- ""
- fmt
- fmt ansi
- fmt json
- fmt json ansi
- fmt registry
- fmt env-filter
- registry
- env-filter
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: cargo check
working-directory: tracing-subscriber
run: cargo check --no-default-features --features "${{ matrix.featureset }}"

features-stable:
# Feature flag tests that run on stable Rust.
# TODO(david): once tracing's MSRV goes up to Rust 1.51, we should be able to switch to
# using cargo's V2 feature resolver (https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions)
# and avoid cd'ing into each crate's directory.
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: "Test log support"
run: cargo test
working-directory: "tracing/test-log-support"
- name: "Test static max level"
run: cargo test
working-directory: "tracing/test_static_max_level_features"
- name: "Test tracing-core no-std support"
run: cargo test --no-default-features
working-directory: tracing-core
- name: "Test tracing no-std support"
run: cargo test --lib --tests --no-default-features
working-directory: tracing
# this skips running doctests under the `--no-default-features` flag,
# as rustdoc isn't aware of cargo's feature flags.
- name: "Test tracing-subscriber no-std support"
run: cargo test --lib --tests --no-default-features
working-directory: tracing-subscriber
- name: "Test tracing-subscriber with liballoc only"
run: cargo test --lib --tests --no-default-features --features "alloc"
working-directory: tracing-subscriber
- name: "Test tracing-subscriber with no default features"
run: cargo test --lib --tests --no-default-features --features "std"
working-directory: tracing-subscriber
6 changes: 6 additions & 0 deletions tracing/test_static_max_level_features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ version = "0.1.0"
publish = false
edition = "2018"

[dependencies]
tracing-core = { path = "../../tracing-core" }

[dependencies.tracing]
path = ".."
features = ["max_level_debug", "release_max_level_info"]

[dev-dependencies]
tokio-test = "0.2.0"
Loading

0 comments on commit 4a044d4

Please sign in to comment.