Skip to content

Commit e7b102d

Browse files
feat: update timed out test counting logic
Since timed out tests can now be treated as either successes or failures, update the logic for handling them. This commit also adds tests for exercising edge cases between `on-timeout="pass"` and retries/flaky tests
1 parent 97e4159 commit e7b102d

File tree

10 files changed

+350
-7
lines changed

10 files changed

+350
-7
lines changed

fixture-data/src/nextest_tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ pub static EXPECTED_TEST_SUITES: LazyLock<IdOrdMap<TestSuiteFixture>> = LazyLock
4747
"test_slow_timeout_subprocess",
4848
TestCaseFixtureStatus::IgnoredPass,
4949
),
50+
TestCaseFixture::new(
51+
"test_slow_timeout_flaky_mod_4",
52+
TestCaseFixtureStatus::IgnoredFail
53+
),
5054
TestCaseFixture::new("test_stdin_closed", TestCaseFixtureStatus::Pass),
5155
TestCaseFixture::new("test_subprocess_doesnt_exit", TestCaseFixtureStatus::Leak),
5256
TestCaseFixture::new("test_subprocess_doesnt_exit_fail", TestCaseFixtureStatus::FailLeak),

fixtures/nextest-tests/.config/nextest.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ test-group = '@global'
8888
[profile.with-timeout-success]
8989
slow-timeout = { period = "10ms", terminate-after = 2, on-timeout = "pass" }
9090

91+
[[profile.with-timeout-success.overrides]]
92+
filter = 'test(=test_slow_timeout_2)'
93+
slow-timeout = { period = "500ms", terminate-after = 2, on-timeout = "fail" }
94+
test-group = '@global'
95+
96+
[[profile.with-timeout-success.overrides]]
97+
filter = 'test(=test_slow_timeout_subprocess)'
98+
slow-timeout = { period = "10ms", terminate-after = 2, on-timeout = "fail" }
99+
100+
[profile.with-timeout-retries-success]
101+
slow-timeout = { period = "10ms", terminate-after = 2, on-timeout = "pass" }
102+
retries = 2
103+
104+
[profile.with-timeout-success-flaky]
105+
slow-timeout = { period = "10ms", terminate-after = 2, on-timeout = "pass" }
106+
retries = 3
107+
91108
[profile.with-junit]
92109
retries = 2
93110

fixtures/nextest-tests/tests/basic.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,16 @@ fn test_slow_timeout_subprocess() {
319319
cmd.output().unwrap();
320320
}
321321

322+
#[test]
323+
#[ignore]
324+
fn test_slow_timeout_flaky_mod_4() {
325+
let nextest_attempt = nextest_attempt();
326+
if nextest_attempt % 4 != 0 {
327+
panic!("Failed because attempt {} % 4 != 0", nextest_attempt)
328+
}
329+
std::thread::sleep(std::time::Duration::from_secs(4));
330+
}
331+
322332
#[test]
323333
fn test_result_failure() -> Result<(), std::io::Error> {
324334
Err(std::io::Error::new(

integration-tests/tests/integration/snapshots/integration__list_with_default_set_bound_all.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: integration-tests/tests/integration/main.rs
33
expression: bound_all_output.stdout_as_str()
4-
snapshot_kind: text
54
---
65
cdylib-example:
76
tests::test_multiply_two_cdylib

integration-tests/tests/integration/snapshots/integration__show_config_test_groups-2.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: integration-tests/tests/integration/main.rs
33
expression: default_profile_all_output.stdout_as_str()
4-
snapshot_kind: text
54
---
65
group: flaky (max threads = 4)
76
(no matches)

integration-tests/tests/integration/snapshots/integration__show_config_test_groups-3.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: integration-tests/tests/integration/main.rs
33
expression: with_retries_output.stdout_as_str()
4-
snapshot_kind: text
54
---
65
group: flaky (max threads = 4)
76
* override for with-retries profile with filter 'test(test_flaky_mod) | test(~test_flaky_mod_4)':

integration-tests/tests/integration/snapshots/integration__show_config_test_groups-4.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: integration-tests/tests/integration/main.rs
33
expression: with_retries_all_output.stdout_as_str()
4-
snapshot_kind: text
54
---
65
group: flaky (max threads = 4)
76
* override for with-retries profile with filter 'test(test_flaky_mod) | test(~test_flaky_mod_4)':

nextest-runner/src/config/elements/slow_timeout.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ mod tests {
205205
206206
; "timeout result failure"
207207
)]
208+
#[test_case(
209+
indoc! {r#"
210+
[profile.default]
211+
slow-timeout = { period = "60s", on-timeout = "pass" }
212+
213+
[profile.ci]
214+
slow-timeout = { period = "30s", on-timeout = "fail" }
215+
"#},
216+
Ok(SlowTimeout { period: Duration::from_secs(60), terminate_after: None, grace_period: Duration::from_secs(10), on_timeout: SlowTimeoutResult::Pass }),
217+
Some(SlowTimeout { period: Duration::from_secs(30), terminate_after: None, grace_period: Duration::from_secs(10), on_timeout: SlowTimeoutResult::Fail })
218+
219+
; "override on-timeout option"
220+
)]
208221
#[test_case(
209222
indoc! {r#"
210223
[profile.default]

nextest-runner/src/reporter/events.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ pub struct RunStats {
534534
/// The number of tests that passed on retry.
535535
pub flaky: usize,
536536

537-
/// The number of tests that failed.
537+
/// The number of tests that failed. Includes `leaky_failed`.
538538
pub failed: usize,
539539

540540
/// The number of failed tests that were slow.
@@ -701,7 +701,20 @@ impl RunStats {
701701
self.failed_slow += 1;
702702
}
703703
}
704-
ExecutionResult::Timeout { .. } => self.failed_timed_out += 1,
704+
ExecutionResult::Timeout {
705+
result: SlowTimeoutResult::Pass,
706+
} => {
707+
self.passed += 1;
708+
self.passed_timed_out += 1;
709+
if run_statuses.len() > 1 {
710+
self.flaky += 1;
711+
}
712+
}
713+
ExecutionResult::Timeout {
714+
result: SlowTimeoutResult::Fail,
715+
} => {
716+
self.failed_timed_out += 1;
717+
}
705718
ExecutionResult::ExecFail => self.exec_failed += 1,
706719
}
707720
}
@@ -1597,7 +1610,18 @@ mod tests {
15971610
initial_run_count: 42,
15981611
not_run: 0
15991612
}),
1600-
"timed out => failure"
1613+
"timed out => failure {:?} {:?}",
1614+
RunStats {
1615+
initial_run_count: 42,
1616+
finished_count: 42,
1617+
failed_timed_out: 1,
1618+
..RunStats::default()
1619+
}
1620+
.summarize_final(),
1621+
FinalRunStats::Failed(RunStatsFailureKind::Test {
1622+
initial_run_count: 42,
1623+
not_run: 0
1624+
}),
16011625
);
16021626
assert_eq!(
16031627
RunStats {

0 commit comments

Comments
 (0)