Skip to content

Commit 1a0af76

Browse files
authored
No cargo test for sort_mem_validation (#21222)
Every time I run tests with `sort_mem_validation` i'm forced to recompile those tests several times, as those trigger `cargo test` (=recompilation with different features). I made it use the existing compiled binary Should save us 2-3 minutes on recompiling code on CI
1 parent 2c03881 commit 1a0af76

File tree

1 file changed

+7
-47
lines changed

1 file changed

+7
-47
lines changed

datafusion/core/tests/memory_limit/memory_limit_validation/sort_mem_validation.rs

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@
2121
//! This file is organized as:
2222
//! - Test runners that spawn individual test processes
2323
//! - Test cases that contain the actual validation logic
24-
use log::info;
25-
use std::sync::Once;
2624
use std::{process::Command, str};
2725

2826
use crate::memory_limit::memory_limit_validation::utils;
2927

30-
static INIT: Once = Once::new();
31-
3228
// ===========================================================================
3329
// Test runners:
3430
// Runners are split into multiple tests to run in parallel
@@ -69,62 +65,26 @@ fn sort_with_mem_limit_2_cols_2_runner() {
6965
spawn_test_process("sort_with_mem_limit_2_cols_2");
7066
}
7167

72-
/// `spawn_test_process` might trigger multiple recompilations and the test binary
73-
/// size might grow indefinitely. This initializer ensures recompilation is only done
74-
/// once and the target size is bounded.
75-
///
76-
/// TODO: This is a hack, can be cleaned up if we have a better way to let multiple
77-
/// test cases run in different processes (instead of different threads by default)
78-
fn init_once() {
79-
INIT.call_once(|| {
80-
let _ = Command::new("cargo")
81-
.arg("test")
82-
.arg("--no-run")
83-
.arg("--package")
84-
.arg("datafusion")
85-
.arg("--test")
86-
.arg("core_integration")
87-
.arg("--features")
88-
.arg("extended_tests")
89-
.env("DATAFUSION_TEST_MEM_LIMIT_VALIDATION", "1")
90-
.output()
91-
.expect("Failed to execute test command");
92-
});
93-
}
94-
95-
/// Helper function that executes a test in a separate process with the required environment
96-
/// variable set. Memory limit validation tasks need to measure memory resident set
97-
/// size (RSS), so they must run in a separate process.
68+
/// Helper function that executes a test in a separate process with the required
69+
/// environment variable set. Re-invokes the current test binary directly,
70+
/// avoiding cargo overhead and recompilation.
9871
fn spawn_test_process(test: &str) {
99-
init_once();
100-
10172
let test_path =
10273
format!("memory_limit::memory_limit_validation::sort_mem_validation::{test}");
103-
info!("Running test: {test_path}");
104-
105-
// Run the test command
106-
let output = Command::new("cargo")
107-
.arg("test")
108-
.arg("--package")
109-
.arg("datafusion")
110-
.arg("--test")
111-
.arg("core_integration")
112-
.arg("--features")
113-
.arg("extended_tests")
114-
.arg("--")
74+
75+
let exe = std::env::current_exe().expect("Failed to get test binary path");
76+
77+
let output = Command::new(exe)
11578
.arg(&test_path)
11679
.arg("--exact")
11780
.arg("--nocapture")
11881
.env("DATAFUSION_TEST_MEM_LIMIT_VALIDATION", "1")
11982
.output()
12083
.expect("Failed to execute test command");
12184

122-
// Convert output to strings
12385
let stdout = str::from_utf8(&output.stdout).unwrap_or("");
12486
let stderr = str::from_utf8(&output.stderr).unwrap_or("");
12587

126-
info!("{stdout}");
127-
12888
assert!(
12989
output.status.success(),
13090
"Test '{}' failed with status: {}\nstdout:\n{}\nstderr:\n{}",

0 commit comments

Comments
 (0)