Skip to content

Commit bb191a5

Browse files
committed
Run tests with nextest and publish results
1 parent 00e924b commit bb191a5

File tree

23 files changed

+138
-58
lines changed

23 files changed

+138
-58
lines changed

.config/nextest.toml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[store]
2+
dir = "target/nextest"
3+
4+
[test-groups]
5+
single-threaded = { max-threads = 1 }
6+
7+
[profile.default]
8+
# Show tests with status skip/pass/slow/fail while running.
9+
status-level = "skip"
10+
# Only show tests with status slow/fail at the end of the run.
11+
final-status-level = "slow"
12+
# Print out output for failing tests as soon as they fail.
13+
failure-output = "immediate"
14+
# Stop the test run on the first failure.
15+
fail-fast = true
16+
17+
[[profile.default.overrides]]
18+
filter = 'test(::single_threaded_tests::)'
19+
test-group = 'single-threaded'
20+
21+
[profile.ci]
22+
# Print out output for failing tests as soon as they fail, and also at the end
23+
# of the run (for easy scrollability).
24+
failure-output = "immediate-final"
25+
# Do not cancel the test run on the first failure.
26+
fail-fast = false
27+
28+
[profile.ci.junit]
29+
# Output a JUnit report into the given file inside 'store.dir/<profile-name>'.
30+
path = "junit.xml"
31+
# The name of the top-level "report" element in JUnit report.
32+
report-name = "nextest-run"
33+
# Don't include stdout and stderr in the JUnit report for successes.
34+
store-success-output = false
35+
# Include the stdout and stderr in the JUnit report for failures.
36+
store-failure-output = true

.github/workflows/coverage.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v4
1616
- name: Install Rust
17-
run: rustup update stable
17+
run: rustup install nightly && rustup default nightly
1818
- name: Install cargo-llvm-cov
1919
uses: taiki-e/install-action@v2
2020
with:
21-
22-
- name: Generate code coverage
23-
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
21+
22+
- name: Generate code coverage (including doc tests)
23+
run: |
24+
cargo llvm-cov --all-features --workspace --no-report nextest
25+
cargo llvm-cov --all-features --workspace --no-report --doc
26+
cargo llvm-cov report --doctests --lcov --output-path lcov.info
2427
- name: Upload coverage to Codecov
2528
uses: codecov/codecov-action@v3
2629
with:

.github/workflows/miri.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
jobs:
66
run-miri:
77
runs-on: ubuntu-latest
8+
env:
9+
CARGO_TERM_COLOR: always
810
steps:
911
- uses: actions/checkout@v2
1012
- uses: actions-rs/toolchain@v1
@@ -13,6 +15,9 @@ jobs:
1315
toolchain: nightly
1416
override: true
1517
components: miri
16-
- run: MIRIFLAGS="-Zmiri-disable-isolation" cargo miri test
18+
- uses: taiki-e/install-action@v2
19+
with:
20+
21+
- run: MIRIFLAGS="-Zmiri-disable-isolation" cargo miri nextest run
1722
# We need to disable isolation because
1823
# "unsupported operation: `clock_gettime` with `REALTIME` clocks not available when isolation is enabled"

.github/workflows/test.yml

+24-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ jobs:
2929
- id: rust-version
3030
# On Windows run happens in a PowerShell, so start bash explicitly
3131
run: bash -c 'echo "version=$(rustc --version)" >> $GITHUB_OUTPUT'
32+
- name: Install cargo nextest
33+
uses: taiki-e/install-action@v2
34+
with:
35+
36+
- name: "Remove nextest CI report"
37+
shell: bash
38+
run: rm -rf target/nextest/ci/junit.xml
3239
- name: Free Disk Space (Ubuntu only)
3340
if: runner.os == 'Linux' && matrix.platform == 'ubuntu-latest'
3441
uses: jlumbroso/[email protected]
@@ -42,19 +49,23 @@ jobs:
4249
swap-storage: true
4350
- name: "[${{ steps.rust-version.outputs.version}}] cargo build --workspace --verbose"
4451
run: cargo build --workspace --verbose
45-
- name: "[${{ steps.rust-version.outputs.version}}] cargo test --workspace --verbose"
46-
run: cargo test --workspace --verbose
47-
env:
48-
RUST_BACKTRACE: 1
49-
- name: "[${{ steps.rust-version.outputs.version}}] cargo test --workspace --verbose -- --ignored --test-threads=1"
50-
run: cargo test --workspace --verbose -- --ignored --test-threads=1
52+
- name: "[${{ steps.rust-version.outputs.version}}] cargo nextest run --workspace --profile ci --verbose"
53+
# Run doc tests with cargo test and run tests with nextest and generate junit.xml
54+
run: cargo test --workspace --doc --verbose && cargo nextest run --workspace --profile ci --verbose
5155
env:
5256
RUST_BACKTRACE: 1
53-
- name: "[${{ steps.rust-version.outputs.version}}] RUSTFLAGS=\"-C prefer-dynamic\" cargo test --package test_spawn_from_lib --features prefer-dynamic -- --ignored"
54-
run: cargo test --package test_spawn_from_lib --features prefer-dynamic -- --ignored
57+
- name: "[${{ steps.rust-version.outputs.version}}] RUSTFLAGS=\"-C prefer-dynamic\" cargo nextest run --package test_spawn_from_lib --features prefer-dynamic"
58+
run: cargo nextest run --package test_spawn_from_lib --features prefer-dynamic
5559
env:
5660
RUSTFLAGS: "-C prefer-dynamic"
5761
RUST_BACKTRACE: 1
62+
- name: Report Test Results
63+
if: success() || failure()
64+
uses: mikepenz/action-junit-report@v4
65+
with:
66+
report_paths: "target/nextest/ci/junit.xml"
67+
check_name: "[${{ matrix.platform }}:${{ matrix.rust_version }}] test report"
68+
include_passed: true
5869

5970
ffi:
6071
name: "FFI #${{ matrix.platform }} ${{ matrix.rust_version }}"
@@ -94,7 +105,8 @@ jobs:
94105
run: rustup install ${{ matrix.rust_version }} && rustup default ${{ matrix.rust_version }}
95106

96107
- id: rust-version
97-
run: echo "version=$(rustc --version)" >> $GITHUB_OUTPUT
108+
# On Windows run happens in a PowerShell, so start bash explicitly
109+
run: bash -c 'echo "version=$(rustc --version)" >> $GITHUB_OUTPUT'
98110

99111
- name: "Generate profiling FFI"
100112
shell: bash
@@ -168,8 +180,9 @@ jobs:
168180
with:
169181
rust_version: cross-centos7
170182
- run: cargo install cross || true
171-
- run: cross build --all
172-
- run: cross test --all
183+
- run: cross build --workspace --target x86_64-unknown-linux-gnu
184+
- run: cross test --workspace --target x86_64-unknown-linux-gnu -- --skip "::single_threaded_tests::"
185+
- run: cross test --workspace --target x86_64-unknown-linux-gnu --exclude bin_tests -- --skip "::tests::" --skip "::api_tests::" --test-threads 1
173186

174187
ffi_bake:
175188
strategy:

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,23 @@ bash build-profiling-ffi.sh /opt/libdatadog
3131

3232
- Rust 1.71 or newer with cargo
3333
- `cmake` and `protoc`
34+
35+
### Running tests
36+
37+
This project uses [cargo-nextest][nt] to run tests.
38+
39+
```bash
40+
cargo nextest run
41+
```
42+
43+
#### Installing cargo-nextest
44+
45+
The simplest way to install [cargo-nextest][nt] is to use `cargo install` like this.
46+
47+
```bash
48+
cargo install --locked '[email protected]'
49+
```
50+
51+
Please note that the locked version is to make sure that it can be built using rust `1.71.1`, and if you are using a newer rust version, then it's enough to limit the version to `0.9.*`.
52+
53+
[nt]: https://nexte.st/

crashtracker/src/api.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ use crate::{
1010
update_receiver_after_fork,
1111
},
1212
crash_info::CrashtrackerMetadata,
13-
update_config, update_metadata, CrashtrackerConfiguration, StacktraceCollection,
13+
update_config, update_metadata, CrashtrackerConfiguration,
1414
};
15-
use ddcommon::tag::Tag;
16-
use ddcommon::Endpoint;
17-
use std::time::Duration;
1815

1916
/// Cleans up after the crash-tracker:
2017
/// Unregister the crash handler, restore the previous handler (if any), and
@@ -101,22 +98,21 @@ pub fn init(
10198
Ok(())
10299
}
103100

104-
#[ignore]
105-
#[allow(dead_code)]
106-
// Ignored tests are still run in CI.
107-
// To test, uncomment the line below than run manually
108101
// We can't run this in the main test runner because it (deliberately) crashes,
109102
// and would make all following tests unrunable.
110103
// To run this test,
111104
// ./build-profiling-ffi /tmp/libdatadog
112105
// mkdir /tmp/crashreports
113106
// look in /tmp/crashreports for the crash reports and output files
114-
// Commented out since `ignore` doesn't work in CI.
115-
//#[test]
107+
#[ignore]
108+
#[test]
116109
fn test_crash() {
117-
use crate::begin_profiling_op;
110+
use crate::{begin_profiling_op, StacktraceCollection};
118111
use chrono::Utc;
119112
use ddcommon::parse_uri;
113+
use ddcommon::tag::Tag;
114+
use ddcommon::Endpoint;
115+
use std::time::Duration;
120116

121117
let time = Utc::now().to_rfc3339();
122118
let dir = "/tmp/crashreports/";

ddcommon-ffi/src/slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'a> From<&'a str> for Slice<'a, c_char> {
143143
}
144144

145145
#[cfg(test)]
146-
mod test {
146+
mod tests {
147147
use std::os::raw::c_char;
148148

149149
use crate::slice::*;

ddcommon-ffi/src/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<T> Default for Vec<T> {
114114
}
115115

116116
#[cfg(test)]
117-
mod test {
117+
mod tests {
118118
use super::*;
119119

120120
#[test]

ddtelemetry-ffi/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ macro_rules! try_c {
105105
pub(crate) use c_setters;
106106

107107
#[cfg(test)]
108-
mod test_c_ffi {
108+
mod tests {
109109
use crate::{builder::*, worker_handle::*};
110110
use ddcommon::{parse_uri, Endpoint};
111111
use ddcommon_ffi as ffi;

ddtelemetry/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl Config {
213213
}
214214

215215
#[cfg(all(test, target_family = "unix"))]
216-
mod test {
216+
mod tests {
217217
use ddcommon::connector::uds;
218218

219219
use super::Config;

ddtelemetry/src/metrics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl MetricContexts {
219219
}
220220

221221
#[cfg(test)]
222-
mod test {
222+
mod tests {
223223
use std::fmt::Debug;
224224

225225
use super::*;

ipc/src/platform/unix/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub unsafe extern "C" fn memfd_create(name: libc::c_void, flags: libc::c_uint) -
2424
}
2525

2626
#[cfg(test)]
27-
mod tests {
27+
mod single_threaded_tests {
2828
use io_lifetimes::OwnedFd;
2929
use pretty_assertions::assert_eq;
3030
use std::{
@@ -90,8 +90,8 @@ mod tests {
9090
assert_eq!(reference_meta, &current_meta);
9191
}
9292

93+
// tests checks global FD state - so it needs to run single-threaded
9394
#[test]
94-
#[ignore] // tests checks global FD state - so it needs to run in non-parallel mode
9595
fn test_channel_metadata_only_provides_valid_owned() {
9696
let reference = get_open_file_descriptors(None).unwrap();
9797
let mut meta = ChannelMetadata::default();

profiling-ffi/src/exporter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ pub unsafe extern "C" fn ddog_CancellationToken_drop(token: Option<&mut Cancella
459459
}
460460

461461
#[cfg(test)]
462-
mod test {
462+
mod tests {
463463
use super::*;
464464
use ddcommon_ffi::Slice;
465465
use serde_json::json;

profiling-ffi/src/profiles.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ pub unsafe extern "C" fn ddog_prof_Profile_reset(
742742
}
743743

744744
#[cfg(test)]
745-
mod test {
745+
mod tests {
746746
use super::*;
747747

748748
#[test]

profiling/src/api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<'a> TryFrom<&'a pprof::Profile> for Profile<'a> {
344344
}
345345

346346
#[cfg(test)]
347-
mod test {
347+
mod tests {
348348
use super::*;
349349

350350
#[test]

profiling/src/collections/identifiable/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn into_pprof_iter<T: PprofItem>(
8585
}
8686

8787
#[cfg(test)]
88-
mod test {
88+
mod tests {
8989
use super::*;
9090

9191
#[test]

profiling/src/internal/observation/observations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl Drop for NonEmptyObservations {
141141
}
142142

143143
#[cfg(test)]
144-
mod test {
144+
mod tests {
145145
use super::*;
146146
use crate::collections::identifiable::*;
147147
use crate::internal::{LabelSetId, StackTraceId};

profiling/src/internal/observation/trimmed_observation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Drop for TrimmedObservation {
123123
}
124124

125125
#[cfg(test)]
126-
mod test {
126+
mod tests {
127127
use super::*;
128128

129129
#[test]

profiling/src/internal/profile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl Profile {
555555
}
556556

557557
#[cfg(test)]
558-
mod api_test {
558+
mod api_tests {
559559
use super::*;
560560

561561
#[test]

profiling/src/pprof/proto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl Profile {
178178
}
179179

180180
#[cfg(test)]
181-
mod test {
181+
mod tests {
182182
use super::*;
183183
use prost::Message;
184184

sidecar-ffi/tests/sidecar.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ fn set_sidecar_per_process() {
2828
#[test]
2929
#[cfg(unix)]
3030
#[cfg_attr(miri, ignore)]
31+
#[cfg_attr(coverage_nightly, ignore)] // this fails on nightly coverage
3132
fn test_ddog_ph_file_handling() {
3233
let fname = CString::new(std::env::temp_dir().join("test_file").to_str().unwrap()).unwrap();
3334
let mode = CString::new("a+").unwrap();

sidecar/src/log.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ pub(crate) fn enable_logging() -> anyhow::Result<()> {
389389
}
390390

391391
#[cfg(test)]
392-
mod test {
392+
mod tests {
393393
use super::{
394394
enable_logging, TemporarilyRetainedKeyParser, TemporarilyRetainedMap, MULTI_LOG_FILTER,
395395
};

0 commit comments

Comments
 (0)