Skip to content

Commit

Permalink
tracing: add static level tests for spans and instrumented fns (tokio…
Browse files Browse the repository at this point in the history
…-rs#1872)

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 kaffarell committed May 22, 2024
1 parent f426714 commit dcb171e
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
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/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ fn last(state: &State, expected: Option<Level>) {
assert_eq!(lvl, expected);
}

#[track_caller]
fn last(state: &State, expected: Option<Level>) {
let lvl = state.last_level.lock().unwrap().take();
assert_eq!(lvl, expected);
}

#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[test]
fn test_static_max_level_events() {
Expand Down

0 comments on commit dcb171e

Please sign in to comment.