From 1582f216fea6f4a342fdf2aea65aa5e5dd5e4f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Sat, 9 May 2026 00:33:34 +0800 Subject: [PATCH] test(ecstore): cover offline capacity snapshots (#2880) --- crates/ecstore/src/set_disk.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/ecstore/src/set_disk.rs b/crates/ecstore/src/set_disk.rs index 7f1a973c0..45063a504 100644 --- a/crates/ecstore/src/set_disk.rs +++ b/crates/ecstore/src/set_disk.rs @@ -5407,6 +5407,27 @@ mod tests { assert!(info[2].drive_path.is_empty(), "offline disk should use runtime snapshot fallback"); } + #[tokio::test] + async fn test_get_disks_info_uses_capacity_snapshot_for_offline_disk() { + let format = FormatV3::new(1, 1); + let (temp_dir, endpoint, disk) = make_formatted_local_disk_for_info_test(0, &format).await; + disk.record_capacity_probe(100, 40, 60); + disk.force_runtime_state_for_test(RuntimeDriveHealthState::Offline); + + let info = get_disks_info(&[Some(disk)], &[endpoint]).await; + assert_eq!(info.len(), 1); + assert_eq!(info[0].state, "offline"); + assert_eq!(info[0].runtime_state.as_deref(), Some("offline")); + assert_eq!(info[0].capacity_observation_source.as_deref(), Some("snapshot")); + assert!(info[0].capacity_observation_age_seconds.unwrap_or(u64::MAX) <= 60); + assert_eq!(info[0].total_space, 100); + assert_eq!(info[0].used_space, 40); + assert_eq!(info[0].available_space, 60); + assert_eq!(info[0].utilization, 40.0); + + drop(temp_dir); + } + #[test] fn test_dangling_meta_errs_count() { // Test counting dangling metadata errors