test: unique temp dir per generations test — parallel runs raced on one SQLite file

This commit is contained in:
itsamejms
2026-09-06 23:23:25 +01:00
parent 03a634fdd0
commit 913345a05e
+6 -4
View File
@@ -159,15 +159,17 @@ impl GenerationStore {
mod tests { mod tests {
use super::*; use super::*;
fn tmp() -> std::path::PathBuf { // ponytail: unique dir per test — both tests previously shared one
let dir = std::env::temp_dir().join(format!("dm-pal-test-{}", std::process::id())); // pid-keyed dir and raced on the same SQLite file (flaky "disk I/O error").
fn tmp(name: &str) -> std::path::PathBuf {
let dir = std::env::temp_dir().join(format!("dm-pal-test-{name}-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir); let _ = std::fs::remove_dir_all(&dir);
dir dir
} }
#[test] #[test]
fn round_trip() { fn round_trip() {
let dir = tmp(); let dir = tmp("round-trip");
let store = GenerationStore::open(&dir).unwrap(); let store = GenerationStore::open(&dir).unwrap();
let id = store let id = store
.add("npc", "Thorin Stonefist", r#"{"name":"Thorin"}"#, Some("Dwarf Fighter")) .add("npc", "Thorin Stonefist", r#"{"name":"Thorin"}"#, Some("Dwarf Fighter"))
@@ -196,7 +198,7 @@ mod tests {
#[test] #[test]
fn clear_all() { fn clear_all() {
let dir = tmp(); let dir = tmp("clear-all");
let store = GenerationStore::open(&dir).unwrap(); let store = GenerationStore::open(&dir).unwrap();
store.add("a", "x", "{}", None).unwrap(); store.add("a", "x", "{}", None).unwrap();
store.add("b", "y", "{}", None).unwrap(); store.add("b", "y", "{}", None).unwrap();