Skip to content

Commit 9cea015

Browse files
committed
tasks_cache: fix race condition in tests
1 parent 652aa6c commit 9cea015

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

devenv-tasks/src/task_cache.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,24 @@ mod tests {
255255
#[sqlx::test]
256256
async fn test_task_cache_initialization() {
257257
let temp_dir = TempDir::new().unwrap();
258-
std::env::set_var("DEVENV_DOTFILE", temp_dir.path().to_str().unwrap());
258+
let db_path = temp_dir.path().join("tasks.db");
259+
260+
// Use with_db_path directly instead of environment variable
261+
let cache = TaskCache::with_db_path(db_path).await.unwrap();
259262

260-
let cache = TaskCache::new().await.unwrap();
261263
// Check if the database connection is valid using a simple query
262264
let result = sqlx::query("SELECT 1").fetch_one(cache.db.pool()).await;
263265
assert!(result.is_ok());
264266
}
265267

266268
#[sqlx::test]
267269
async fn test_file_modification_detection() {
268-
let dotfile_dir = TempDir::new().unwrap();
269-
std::env::set_var("DEVENV_DOTFILE", dotfile_dir.path().to_str().unwrap());
270+
let db_temp_dir = TempDir::new().unwrap();
271+
let db_path = db_temp_dir.path().join("tasks-file-mod.db");
270272

271-
let cache = TaskCache::new().await.unwrap();
272-
let temp_dir = TempDir::new().unwrap();
273-
let file_path = temp_dir.path().join("test.txt");
273+
let cache = TaskCache::with_db_path(db_path).await.unwrap();
274+
let test_temp_dir = TempDir::new().unwrap();
275+
let file_path = test_temp_dir.path().join("test.txt");
274276

275277
// Create a test file
276278
{
@@ -338,12 +340,12 @@ mod tests {
338340

339341
#[sqlx::test]
340342
async fn test_directory_modification_detection() {
341-
let dotfile_dir = TempDir::new().unwrap();
342-
std::env::set_var("DEVENV_DOTFILE", dotfile_dir.path().to_str().unwrap());
343+
let db_temp_dir = TempDir::new().unwrap();
344+
let db_path = db_temp_dir.path().join("tasks-dir-mod.db");
343345

344-
let cache = TaskCache::new().await.unwrap();
345-
let temp_dir = TempDir::new().unwrap();
346-
let dir_path = temp_dir.path().join("test_dir");
346+
let cache = TaskCache::with_db_path(db_path).await.unwrap();
347+
let test_temp_dir = TempDir::new().unwrap();
348+
let dir_path = test_temp_dir.path().join("test_dir");
347349
std::fs::create_dir(&dir_path).unwrap();
348350

349351
let task_name = "test_task_dir";

0 commit comments

Comments
 (0)