Skip to content

Commit

Permalink
fix(fs-storage): add delay in tests after file write
Browse files Browse the repository at this point in the history
Signed-off-by: Tarek <[email protected]>
  • Loading branch information
tareknaser committed Jun 12, 2024
1 parent 3831efc commit 876fb36
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fs-storage/src/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ where
let mut file = File::create(&self.path)?;
file.write_all(serde_json::to_string_pretty(&self.data)?.as_bytes())?;
file.flush()?;
file.sync_all()?;

let new_timestamp = fs::metadata(&self.path)?.modified()?;
if new_timestamp == self.modified {
Expand Down Expand Up @@ -368,13 +369,15 @@ mod tests {
let mut file_storage =
FileStorage::new("TestStorage".to_string(), &storage_path).unwrap();
file_storage.write_fs().unwrap();
std::thread::sleep(std::time::Duration::from_secs(1));

file_storage.set("key1".to_string(), "value1".to_string());
let before_write = fs::metadata(&storage_path)
.unwrap()
.modified()
.unwrap();
file_storage.write_fs().unwrap();
std::thread::sleep(std::time::Duration::from_secs(1));
let after_write = fs::metadata(&storage_path)
.unwrap()
.modified()
Expand All @@ -395,6 +398,7 @@ mod tests {
let mut file_storage =
FileStorage::new("TestStorage".to_string(), &storage_path).unwrap();
file_storage.write_fs().unwrap();
std::thread::sleep(std::time::Duration::from_secs(1));
assert_eq!(file_storage.sync_status().unwrap(), SyncStatus::InSync);

file_storage.set("key1".to_string(), "value1".to_string());
Expand All @@ -403,6 +407,7 @@ mod tests {
SyncStatus::StorageStale
);
file_storage.write_fs().unwrap();
std::thread::sleep(std::time::Duration::from_secs(1));
assert_eq!(file_storage.sync_status().unwrap(), SyncStatus::InSync);

// External data manipulation
Expand All @@ -418,6 +423,7 @@ mod tests {
);

mirror_storage.write_fs().unwrap();
std::thread::sleep(std::time::Duration::from_secs(1));
assert_eq!(mirror_storage.sync_status().unwrap(), SyncStatus::InSync);

// receive updates from external data manipulation
Expand Down

0 comments on commit 876fb36

Please sign in to comment.