mirror of
https://github.com/rustfs/rustfs.git
synced 2026-10-04 12:31:36 +00:00
fix(test): synchronize top-disk fixture writes with sampling (#8243)
This commit is contained in:
@@ -22,6 +22,9 @@ use super::top_api::{MAX_SAFE_INTEGER, TopCaptureError, TopCaptureRequest, TopRe
|
||||
const TOOL_ID: &str = "top.disk";
|
||||
pub const TOP_DISK_CAPABILITY: &str = "top.disk@1";
|
||||
|
||||
#[cfg(all(test, target_os = "linux"))]
|
||||
pub(super) static AFTER_INITIAL_DISK_SNAPSHOT: std::sync::OnceLock<fn()> = std::sync::OnceLock::new();
|
||||
|
||||
/// Closed local-service request for supported top tools: no process selector, paths, or supplied provenance.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||
@@ -89,6 +92,10 @@ pub async fn capture_top_disk(
|
||||
}
|
||||
let mut sampler = rustfs_io_metrics::ProcessSampler::new();
|
||||
let before = process_snapshot(&mut sampler)?;
|
||||
#[cfg(test)]
|
||||
if let Some(write_fixture_data) = AFTER_INITIAL_DISK_SNAPSHOT.get() {
|
||||
write_fixture_data();
|
||||
}
|
||||
if !request.wait_window(TOOL_ID, cancel).await? {
|
||||
return request.cancelled(TOOL_ID);
|
||||
}
|
||||
|
||||
@@ -2706,6 +2706,16 @@ mod tests {
|
||||
let Some(state) = std::env::var_os("RUSTFS_TEST_TOP_DISK_STATE") else {
|
||||
return;
|
||||
};
|
||||
super::super::top_disk::AFTER_INITIAL_DISK_SNAPSHOT
|
||||
.set(|| {
|
||||
// Keep real writes between the collector's snapshots in this dedicated child.
|
||||
let mut file = tempfile::tempfile().expect("create top.disk fixture file");
|
||||
for _ in 0..32 {
|
||||
file.write_all(&[1u8; 4096]).expect("write top.disk fixture data");
|
||||
}
|
||||
file.sync_all().expect("flush top.disk fixture data");
|
||||
})
|
||||
.expect("install top.disk fixture writer once");
|
||||
let state = std::path::PathBuf::from(state);
|
||||
let stop = CancellationToken::new();
|
||||
let input_stop = stop.clone();
|
||||
@@ -2715,12 +2725,7 @@ mod tests {
|
||||
});
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
let runtime = spawn_local_trace_capture_runtime(&state, &stop).unwrap();
|
||||
let mut file = tempfile::tempfile().unwrap();
|
||||
while !stop.is_cancelled() {
|
||||
file.write_all(&[1u8; 4096]).unwrap();
|
||||
file.sync_all().unwrap();
|
||||
tokio::time::sleep(Duration::from_millis(5)).await;
|
||||
}
|
||||
stop.cancelled().await;
|
||||
runtime.shutdown().await;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user