Skip to content

Commit

Permalink
Add MRE for file metadata timestamp not updated on write_fs
Browse files Browse the repository at this point in the history
  • Loading branch information
twitu committed Jun 11, 2024
1 parent 4a13396 commit 242abd4
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions fs-storage/src/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,33 @@ mod tests {
assert!(!storage_path.exists());
}

#[test]
fn test_file_metadata_timestamp_updated() {
let temp_dir =
TempDir::new("tmp").expect("Failed to create temporary directory");
let storage_path = temp_dir.path().join("teststorage.txt");

let mut file_storage =
FileStorage::new("TestStorage".to_string(), &storage_path).unwrap();
file_storage.write_fs().unwrap();

file_storage.set("key1".to_string(), "value1".to_string());
let before_write = fs::metadata(&storage_path)
.unwrap()
.modified()
.unwrap();
file_storage.write_fs().unwrap();
let after_write = fs::metadata(&storage_path)
.unwrap()
.modified()
.unwrap();
println!(
"before_write: {:?}, after_write: {:?}",
before_write, after_write
);
assert!(before_write < after_write);
}

#[test]
fn test_file_storage_is_storage_updated() {
let temp_dir =
Expand Down Expand Up @@ -390,20 +417,7 @@ mod tests {
SyncStatus::StorageStale
);

let before_write = fs::metadata(&storage_path)
.unwrap()
.modified()
.unwrap();
mirror_storage.write_fs().unwrap();
let after_write = fs::metadata(&storage_path)
.unwrap()
.modified()
.unwrap();
println!(
"before_write: {:?}, after_write: {:?}",
before_write, after_write
);
assert!(before_write < after_write);
assert_eq!(mirror_storage.sync_status().unwrap(), SyncStatus::InSync);

// receive updates from external data manipulation
Expand Down

0 comments on commit 242abd4

Please sign in to comment.