mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-24 10:09:32 -06:00
xtask: use unique temporary directories for bench tests (#2196)
This commit is contained in:
Generated
+1
@@ -6628,6 +6628,7 @@ name = "xtask"
|
||||
version = "0.16.0"
|
||||
dependencies = [
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -7,3 +7,5 @@ publish = false
|
||||
|
||||
[dependencies]
|
||||
serde_json = { workspace = true }
|
||||
|
||||
tempfile = "3"
|
||||
|
||||
+4
-14
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user