Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

xtask: use unique temporary directories for bench tests (#2196)

Dylan M. Taylorbd3ae8ab14e1
diff --git a/Cargo.lock b/Cargo.lock
index bba6288d0..8585b9b48 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6628,6 +6628,7 @@ name = "xtask"
version = "0.16.0"
dependencies = [
"serde_json",
+ "tempfile",
]
[[package]]
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index df7dfa877..ea80b285a 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -7,3 +7,5 @@ publish = false
[dependencies]
serde_json = { workspace = true }
+
+tempfile = "3"
diff --git a/xtask/tests/bench.rs b/xtask/tests/bench.rs
index 919b5b94c..641b0d56b 100644
--- a/xtask/tests/bench.rs
+++ b/xtask/tests/bench.rs
@@ -1,20 +1,15 @@
//! Regression gates must fail when benchmark evidence is corrupt or incomplete.
use serde_json::{Value, json};
-use std::path::PathBuf;
use std::process::{Command, Output};
-struct ResultsDir(PathBuf);
+struct ResultsDir(tempfile::TempDir);
impl ResultsDir {
fn new() -> Self {
- use std::sync::atomic::{AtomicU64, Ordering};
- static NEXT: AtomicU64 = AtomicU64::new(0);
- let dir = std::env::temp_dir().join(format!("effectcraft-bench-{}-{}", std::process::id(), NEXT.fetch_add(1, Ordering::Relaxed)));
- std::fs::create_dir_all(&dir).unwrap();
- Self(dir)
+ Self(tempfile::Builder::new().prefix("effectcraft-bench-").tempdir().unwrap())
}
fn compare(&self, old: &str, new: &str, gate: bool) -> Output {
- let baseline = self.0.join("baseline.jsonl");
- let candidate = self.0.join("candidate.jsonl");
+ let baseline = self.0.path().join("baseline.jsonl");
+ let candidate = self.0.path().join("candidate.jsonl");
std::fs::write(&baseline, old).unwrap();
std::fs::write(&candidate, new).unwrap();
let mut command = Command::new(env!("CARGO_BIN_EXE_xtask"));
@@ -25,11 +20,6 @@ impl ResultsDir {
command.output().unwrap()
}
}
-impl Drop for ResultsDir {
- fn drop(&mut self) {
- let _ = std::fs::remove_dir_all(&self.0);
- }
-}
fn row(scenario: &str, ok: bool) -> Value {
json!({"scenario": scenario, "run": "full", "ok": ok,