Skip to content

Commit 8122e70

Browse files
Kontinuationpaleolimbot
authored andcommitted
fix(rust/sedona-testing): serialize env-mutating tests with a mutex to prevent race conditions (#685)
1 parent 5e89955 commit 8122e70

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

rust/sedona-testing/src/data.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,17 @@ pub fn sedona_testing_dir() -> Result<String> {
128128
#[cfg(test)]
129129
mod test {
130130
use super::*;
131+
use std::sync::Mutex;
132+
133+
// These tests mutate global states including environment variables so they must
134+
// run serially. The SERIAL_TEST mutex ensures that only one test executes at a time,
135+
// preventing race conditions when modifying and restoring environment variables.
136+
static SERIAL_TEST: Mutex<()> = Mutex::new(());
131137

132138
#[test]
133139
fn example_files() {
140+
let _guard = SERIAL_TEST.lock().unwrap();
141+
134142
// By default this should resolve, since we are in a test!
135143
assert!(geoarrow_data_dir().is_ok());
136144
assert!(test_geoparquet("natural-earth", "countries").is_ok());
@@ -157,6 +165,8 @@ mod test {
157165

158166
#[test]
159167
fn sedona_testing_dir_resolves() {
168+
let _guard = SERIAL_TEST.lock().unwrap();
169+
160170
assert!(sedona_testing_dir().is_ok());
161171

162172
env::set_var("SEDONA_TESTING_DIR", "this_directory_does_not_exist");

0 commit comments

Comments
 (0)