Skip to content

Commit 815be98

Browse files
committed
[nextest-runner] set NEXTEST_TEST_GLOBAL_SLOT and NEXTEST_TEST_GROUP_SLOT
Set these to environment variables that are *unique* for the lifetime of the test, and *compact* (smallest possible number can be assigned).
1 parent 1e1201b commit 815be98

12 files changed

+151
-54
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ enable-ansi-support = "0.2.1"
5858
env_logger = { version = "0.11.6", default-features = false }
5959
fixture-data = { path = "fixture-data" }
6060
fs-err = "3.1.0"
61-
future-queue = "0.3.0"
61+
future-queue = "0.4.0"
6262
futures = "0.3.31"
6363
globset = "0.4.15"
6464
guppy = "0.17.14"
@@ -156,8 +156,8 @@ strip = "none"
156156
nextest-workspace-hack = { path = "workspace-hack" }
157157

158158
# Uncomment for testing.
159-
# [patch.crates-io]
160159
# cargo_metadata = { path = "../cargo_metadata" }
160+
# future-queue = { path = "../future-queue" }
161161
# target-spec = { path = "../guppy/target-spec" }
162162
# target-spec-miette = { path = "../guppy/target-spec-miette" }
163163
# quick-junit = { path = "../quick-junit" }

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ leak-timeout = '1s'
3333
[profile.with-retries]
3434
retries = 2
3535

36+
# Test out serial tests.
37+
[[profile.with-retries.overrides]]
38+
filter = "test(=test_success) | test(=test_execute_bin)"
39+
test-group = 'serial'
40+
3641
# Run test_flaky_mod_6 with 5 retries (6 tries) rather than 2.
3742
[[profile.with-retries.overrides]]
3843
filter = "test(=test_flaky_mod_6)"
@@ -91,6 +96,9 @@ max-threads = 4
9196
[test-groups.unused]
9297
max-threads = 20
9398

99+
[test-groups.serial]
100+
max-threads = 1
101+
94102
[script.my-script-unix]
95103
command = './scripts/my-script.sh'
96104

fixtures/nextest-tests/tests/basic.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::{env, io::Read, path::PathBuf};
33

44
#[test]
55
fn test_success() {
6+
assert_with_retries_serial();
7+
68
// Check that MY_ENV_VAR (set by the setup script) isn't enabled.
79
assert_eq!(
810
std::env::var("MY_ENV_VAR"),
@@ -104,6 +106,7 @@ fn test_ignored_fail() {
104106
/// Test that a binary can be successfully executed.
105107
#[test]
106108
fn test_execute_bin() {
109+
assert_with_retries_serial();
107110
nextest_tests::test_execute_bin_helper();
108111
}
109112

@@ -157,6 +160,11 @@ fn test_cargo_env_vars() {
157160
.expect("NEXTEST_RUN_ID must be set")
158161
.parse::<uuid::Uuid>()
159162
.expect("NEXTEST_RUN_ID must be a UUID");
163+
let global_slot = std::env::var("NEXTEST_TEST_GLOBAL_SLOT")
164+
.expect("NEXTEST_TEST_GLOBAL_SLOT must be set")
165+
.parse::<u64>()
166+
.expect("NEXTEST_TEST_GLOBAL_SLOT must be a u64");
167+
println!("NEXTEST_TEST_GLOBAL_SLOT = {global_slot}");
160168

161169
assert_eq!(
162170
std::env::var("NEXTEST_EXECUTION_MODE").as_deref(),
@@ -369,3 +377,19 @@ fn test_stdin_closed() {
369377
.expect("reading from /dev/null succeeded")
370378
);
371379
}
380+
381+
/// Asserts that if the with-retries profile is set, the test group slot is 0.
382+
///
383+
/// This should be called if and only if the test-group is serial.
384+
fn assert_with_retries_serial() {
385+
let profile = std::env::var("NEXTEST_PROFILE").expect("NEXTEST_PROFILE should be set");
386+
let group_slot =
387+
std::env::var("NEXTEST_TEST_GROUP_SLOT").expect("NEXTEST_TEST_GROUP_SLOT should be set");
388+
if profile == "with-retries" {
389+
// Check that NEXTEST_TEST_GROUP_SLOT is set.
390+
// This test is in a serial group, so the group slot should be 0.
391+
assert_eq!(group_slot, "0", "NEXTEST_TEST_GROUP_SLOT should be 0");
392+
} else {
393+
assert_eq!(group_slot, "none", "NEXTEST_TEST_GROUP_SLOT should be none");
394+
}
395+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ snapshot_kind: text
55
---
66
group: flaky (max threads = 4)
77
(no matches)
8+
group: serial (max threads = 1)
9+
(no matches)
810
group: unused (max threads = 20)
911
(no matches)
1012
group: @global

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
---
22
source: integration-tests/tests/integration/main.rs
33
expression: with_retries_output.stdout_as_str()
4+
snapshot_kind: text
45
---
56
group: flaky (max threads = 4)
67
* override for with-retries profile with filter 'test(test_flaky_mod) | test(~test_flaky_mod_4)':
78
nextest-tests::basic:
89
test_flaky_mod_4
910
test_flaky_mod_6
11+
group: serial (max threads = 1)
12+
* override for with-retries profile with filter 'test(=test_success) | test(=test_execute_bin)':
13+
nextest-tests::basic:
14+
test_execute_bin
15+
test_success
1016
group: unused (max threads = 20)
1117
(no matches)
12-

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ group: flaky (max threads = 4)
88
nextest-tests::basic:
99
test_flaky_mod_4
1010
test_flaky_mod_6
11+
group: serial (max threads = 1)
12+
* override for with-retries profile with filter 'test(=test_success) | test(=test_execute_bin)':
13+
nextest-tests::basic:
14+
test_execute_bin
15+
test_success
1116
group: unused (max threads = 20)
1217
(no matches)
1318
group: @global
@@ -24,15 +29,13 @@ group: @global
2429
nextest-tests::basic:
2530
test_cargo_env_vars
2631
test_cwd
27-
test_execute_bin
2832
test_failure_assert
2933
test_failure_error
3034
test_failure_should_panic
3135
test_result_failure
3236
test_stdin_closed
3337
test_subprocess_doesnt_exit
3438
test_subprocess_doesnt_exit_fail
35-
test_success
3639
test_success_should_panic
3740
nextest-tests::other:
3841
other_test_success

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
---
22
source: integration-tests/tests/integration/main.rs
33
expression: with_termination_output.stdout_as_str()
4+
snapshot_kind: text
45
---
56
group: flaky (max threads = 4)
67
(no matches)
8+
group: serial (max threads = 1)
9+
(no matches)
710
group: unused (max threads = 20)
811
(no matches)
912
group: @global
1013
* override for with-termination profile with filter 'test(=test_slow_timeout_2)':
1114
nextest-tests::basic:
12-

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ snapshot_kind: text
55
---
66
group: flaky (max threads = 4)
77
(no matches)
8+
group: serial (max threads = 1)
9+
(no matches)
810
group: unused (max threads = 20)
911
(no matches)
1012
group: @global

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
---
22
source: integration-tests/tests/integration/main.rs
33
expression: default_profile_output.stdout_as_str()
4+
snapshot_kind: text
45
---
56
group: flaky (max threads = 4)
67
(no matches)
8+
group: serial (max threads = 1)
9+
(no matches)
710
group: unused (max threads = 20)
811
(no matches)
9-

0 commit comments

Comments
 (0)