From 31e90bdede59e65473496aef983c0c7cc39f95f8 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 7 Sep 2022 13:16:35 +0900 Subject: [PATCH] tests: use tempfile::TempDir instead of env::temp_dir() + random number Otherwise /tmp/test- file would be left. --- lib/src/lock.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/src/lock.rs b/lib/src/lock.rs index 13df1c207..520e5087c 100644 --- a/lib/src/lock.rs +++ b/lib/src/lock.rs @@ -72,16 +72,17 @@ impl Drop for FileLock { #[cfg(test)] mod tests { use std::cmp::max; - use std::{env, thread}; + use std::thread; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use super::*; + use crate::testutils; #[test] fn lock_basic() { - let number: u32 = rand::random(); - let lock_path = env::temp_dir().join(format!("test-{}.lock", number)); + let temp_dir = testutils::new_temp_dir(); + let lock_path = temp_dir.path().join("test.lock"); assert!(!lock_path.exists()); { let _lock = FileLock::lock(lock_path.clone()); @@ -92,9 +93,9 @@ mod tests { #[test] fn lock_concurrent() { - let number: u32 = rand::random(); - let data_path = env::temp_dir().join(format!("test-{}", number)); - let lock_path = env::temp_dir().join(format!("test-{}.lock", number)); + let temp_dir = testutils::new_temp_dir(); + let data_path = temp_dir.path().join("test"); + let lock_path = temp_dir.path().join("test.lock"); let mut data_file = OpenOptions::new() .create(true) .write(true)