test(peer): consolidate temp dir helper
Move the repeated test TempDir implementations into a single peer test_support module. The shared helper keeps the existing automatic cleanup behavior and uses an atomic suffix plus timestamp so parallel tests do not collide on the same path. This is intentionally limited to test hygiene. It does not change the availability model, split download.rs, or touch production scan/install behavior beyond importing the shared helper from test modules. Test Plan: - git diff --check - just fmt - just clippy - just test Follow-up-Plan: FOLLOW_UP_2.md
This commit is contained in:
@@ -398,11 +398,7 @@ mod tests {
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
path::{Path, PathBuf},
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicU64, Ordering},
|
||||
},
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use tokio::sync::{RwLock, mpsc};
|
||||
@@ -414,40 +410,9 @@ mod tests {
|
||||
Unpacker,
|
||||
context::{Ctx, OperationKind},
|
||||
peer_db::PeerGameDB,
|
||||
test_support::TempDir,
|
||||
};
|
||||
|
||||
struct TempDir(PathBuf);
|
||||
|
||||
static NEXT_TEMP_ID: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
impl TempDir {
|
||||
fn new() -> Self {
|
||||
let mut path = std::env::temp_dir();
|
||||
let unique_id = NEXT_TEMP_ID.fetch_add(1, Ordering::Relaxed);
|
||||
path.push(format!(
|
||||
"lanspread-stream-{}-{}-{}",
|
||||
std::process::id(),
|
||||
unique_id,
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_nanos()
|
||||
));
|
||||
std::fs::create_dir_all(&path).expect("temp dir should be created");
|
||||
Self(path)
|
||||
}
|
||||
|
||||
fn path(&self) -> &Path {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TempDir {
|
||||
fn drop(&mut self) {
|
||||
let _ = std::fs::remove_dir_all(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
struct NoopUnpacker;
|
||||
|
||||
impl Unpacker for NoopUnpacker {
|
||||
@@ -488,7 +453,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn get_game_response_respects_serve_gates() {
|
||||
let temp = TempDir::new();
|
||||
let temp = TempDir::new("lanspread-stream");
|
||||
write_file(&temp.path().join("ready").join("version.ini"), b"20250101");
|
||||
write_file(
|
||||
&temp.path().join("non-catalog").join("version.ini"),
|
||||
@@ -531,7 +496,7 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn file_transfer_dispatch_respects_serve_gates() {
|
||||
let temp = TempDir::new();
|
||||
let temp = TempDir::new("lanspread-stream");
|
||||
write_file(&temp.path().join("ready").join("version.ini"), b"20250101");
|
||||
write_file(
|
||||
&temp.path().join("non-catalog").join("version.ini"),
|
||||
|
||||
Reference in New Issue
Block a user