From a379874a910e8f9ce9140ef81e9b0607817c9802 Mon Sep 17 00:00:00 2001 From: Phoebe Goldman Date: Mon, 2 Oct 2023 13:18:57 -0400 Subject: [PATCH] SDK tests use a tempdir as STDB_PATH, rather than ~/.spacetime (#348) We've had continual issues with test isolation when developing breaking changes. This commit doesn't fully address those, but is a step in the right direction: the SDK tests now create a tempdir as their `STDB_PATH`, rather than using `~/.spacetime`. --- Cargo.lock | 15 ++++++--------- Cargo.toml | 2 +- crates/testing/Cargo.toml | 1 + crates/testing/src/sdk.rs | 13 +++++++++++-- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36a6961de25..e7d3e7bc03c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1472,12 +1472,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.9.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fd-lock" @@ -4494,6 +4491,7 @@ dependencies = [ "spacetimedb-core", "spacetimedb-lib", "spacetimedb-standalone", + "tempfile", "tokio", "wasmbin", ] @@ -4784,15 +4782,14 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.6.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ - "autocfg", "cfg-if", "fastrand", "redox_syscall 0.3.5", - "rustix 0.37.21", + "rustix 0.38.1", "windows-sys 0.48.0", ] diff --git a/Cargo.toml b/Cargo.toml index 723adb80ae5..f9586c56351 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -157,7 +157,7 @@ syntect = { version = "5.0.0", default-features = false, features = [ ] } tabled = "0.8.0" tempdir = "0.3.7" -tempfile = "3.3" +tempfile = "3.8" termcolor = "1.2.0" thiserror = "1.0.37" tokio = { version = "1.25.1", features = ["full"] } diff --git a/crates/testing/Cargo.toml b/crates/testing/Cargo.toml index 3469275d9f9..6afb07a61cc 100644 --- a/crates/testing/Cargo.toml +++ b/crates/testing/Cargo.toml @@ -19,6 +19,7 @@ duct.workspace = true lazy_static.workspace = true rand.workspace = true prost.workspace = true +tempfile.workspace = true [dev-dependencies] serial_test.workspace = true diff --git a/crates/testing/src/sdk.rs b/crates/testing/src/sdk.rs index ae7a1add6dc..e6abaacfaf0 100644 --- a/crates/testing/src/sdk.rs +++ b/crates/testing/src/sdk.rs @@ -7,11 +7,20 @@ use std::{collections::HashSet, fs::create_dir_all, sync::Mutex}; use crate::invoke_cli; use crate::modules::{module_path, CompiledModule}; use std::path::Path; +use tempfile::TempDir; pub fn ensure_standalone_process() { lazy_static! { - static ref JOIN_HANDLE: Mutex>> = - Mutex::new(Some(std::thread::spawn(|| invoke_cli(&["start"])))); + static ref JOIN_HANDLE: Mutex>> = { + let stdb_path = TempDir::with_prefix("stdb-sdk-test") + .expect("Failed to create tempdir") + // TODO: This leaks the tempdir. + // We need the tempdir to live for the duration of the process, + // and all the options for post-`main` cleanup seem sketchy. + .into_path(); + std::env::set_var("STDB_PATH", stdb_path); + Mutex::new(Some(std::thread::spawn(|| invoke_cli(&["start"])))) + }; } let mut join_handle = JOIN_HANDLE.lock().unwrap();