From 876fb3647f2fe9d59a8ba39c0d1770055c3c4691 Mon Sep 17 00:00:00 2001 From: Tarek Date: Wed, 12 Jun 2024 23:33:17 +0300 Subject: [PATCH] fix(fs-storage): add delay in tests after file write Signed-off-by: Tarek --- fs-storage/src/file_storage.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs-storage/src/file_storage.rs b/fs-storage/src/file_storage.rs index 276c808c..eea8e4a7 100644 --- a/fs-storage/src/file_storage.rs +++ b/fs-storage/src/file_storage.rs @@ -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 { @@ -368,6 +369,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)); file_storage.set("key1".to_string(), "value1".to_string()); let before_write = fs::metadata(&storage_path) @@ -375,6 +377,7 @@ mod tests { .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() @@ -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()); @@ -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 @@ -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