From e9320497fbe44cff9ada434df0fef3008d500ecd Mon Sep 17 00:00:00 2001 From: Tarek Date: Wed, 12 Jun 2024 02:09:58 +0300 Subject: [PATCH] try to isolate the error Signed-off-by: Tarek --- fs-storage/src/file_storage.rs | 41 ++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/fs-storage/src/file_storage.rs b/fs-storage/src/file_storage.rs index 276c808c..cc51d85f 100644 --- a/fs-storage/src/file_storage.rs +++ b/fs-storage/src/file_storage.rs @@ -359,31 +359,38 @@ mod tests { assert!(!storage_path.exists()); } + use std::io::Write; + #[test] fn test_file_metadata_timestamp_updated() { + // Create a temporary file let temp_dir = TempDir::new("tmp").expect("Failed to create temporary directory"); - let storage_path = temp_dir.path().join("teststorage.txt"); + let storage_path = temp_dir.path().join("test_storage.txt"); - let mut file_storage = - FileStorage::new("TestStorage".to_string(), &storage_path).unwrap(); - file_storage.write_fs().unwrap(); + // Write to the file using write_all adn flush + let mut file = + fs::File::create(&storage_path).expect("Failed to create file"); + file.write_all(b"test1") + .expect("Failed to write to file"); + file.flush().expect("Failed to flush file"); - file_storage.set("key1".to_string(), "value1".to_string()); - let before_write = fs::metadata(&storage_path) - .unwrap() + let timestamp_before = fs::metadata(&storage_path) + .expect("Failed to get metadata") .modified() - .unwrap(); - file_storage.write_fs().unwrap(); - let after_write = fs::metadata(&storage_path) - .unwrap() + .expect("Failed to get modified time"); + + // write to the file again + file.write_all(b"test2") + .expect("Failed to write to file"); + file.flush().expect("Failed to flush file"); + + let timestamp_after = fs::metadata(&storage_path) + .expect("Failed to get metadata") .modified() - .unwrap(); - println!( - "before_write: {:?}, after_write: {:?}", - before_write, after_write - ); - assert!(before_write < after_write); + .expect("Failed to get modified time"); + + assert!(timestamp_after > timestamp_before); } #[test]