mirror of
https://github.com/rustfs/rustfs.git
synced 2026-12-03 06:36:35 +00:00
test(connect): prepare top fixtures before capture
Complete executable provenance before publishing local fixture sockets, then wait for explicit preparation and socket sealing before creating capture consent. Reuse the same bounded readiness and child cleanup across top.api, top.rpc, top.locks, and top.disk tests. Preserve production IPC limits, capture windows, and the original event, IO, identity, and archive-signature assertions. Co-Authored-By: heihutu <heihutu@gmail.com> Co-Authored-By: zhi22915 <qiuzgang@gmail.com> Co-Authored-By: qunjiazhu <qunjiazhu@gmail.com>
This commit is contained in:
@@ -1933,6 +1933,27 @@ mod tests {
|
||||
assert!(provenance.is_valid(), "profile capture requires valid executable provenance");
|
||||
}
|
||||
|
||||
const TOP_PREPARED_FILE: &str = "top-provenance-ready";
|
||||
|
||||
async fn prepare_top_test_provenance(state: &std::path::Path) {
|
||||
prepare_profile_test_provenance().await;
|
||||
std::fs::write(state.join(TOP_PREPARED_FILE), b"ready").expect("top fixture provenance ready marker");
|
||||
}
|
||||
|
||||
async fn wait_for_top_test_child(
|
||||
child: &mut tokio::process::Child,
|
||||
state: &std::path::Path,
|
||||
) -> Result<(), LocalTraceCaptureError> {
|
||||
// Cold executable hashing has a fixture budget, separate from the
|
||||
// sealed-socket and production IPC response deadlines.
|
||||
wait_for_profile_child_marker(child, &state.join(TOP_PREPARED_FILE), Duration::from_secs(120))
|
||||
.await
|
||||
.map_err(LocalTraceCaptureError::Io)?;
|
||||
wait_for_sealed_socket(state)
|
||||
.await
|
||||
.map_err(|_| LocalTraceCaptureError::Protocol)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn local_runtime_captures_server_process_events() {
|
||||
@@ -2446,10 +2467,9 @@ mod tests {
|
||||
});
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
rustfs_credentials::set_global_rpc_secret("top-rpc-local-test-secret".to_owned()).unwrap();
|
||||
prepare_top_test_provenance(std::path::Path::new(&state)).await;
|
||||
let runtime = spawn_local_trace_capture_runtime(std::path::Path::new(&state), &stop).unwrap();
|
||||
let emit = async {
|
||||
// Hashing the CI test executable must finish before timing subscriber readiness.
|
||||
super::super::job_delivery::executable_provenance().await.unwrap();
|
||||
tokio::time::timeout(Duration::from_secs(10), async {
|
||||
while telemetry_trace_subscriber_count() == 0 {
|
||||
tokio::task::yield_now().await;
|
||||
@@ -2528,9 +2548,7 @@ mod tests {
|
||||
use std::io::Read as _;
|
||||
let state = tempfile::tempdir().unwrap();
|
||||
std::fs::set_permissions(state.path(), std::fs::Permissions::from_mode(0o700)).unwrap();
|
||||
let mut request = disk_request(state.path());
|
||||
request.window_millis = 500;
|
||||
let mut child = std::process::Command::new(std::env::current_exe().unwrap())
|
||||
let mut child = tokio::process::Command::new(std::env::current_exe().unwrap())
|
||||
.args([
|
||||
"connect::diagnostics::trace_runtime::tests::local_top_rpc_service_child",
|
||||
"--exact",
|
||||
@@ -2538,17 +2556,22 @@ mod tests {
|
||||
])
|
||||
.env("RUSTFS_TEST_TOP_RPC_STATE", state.path())
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.kill_on_drop(true)
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let ready = wait_for_sealed_socket(state.path()).await;
|
||||
let result = if ready.is_ok() {
|
||||
super::request_local_top_rpc(state.path(), request.clone(), &CancellationToken::new()).await
|
||||
} else {
|
||||
Err(LocalTraceCaptureError::Protocol)
|
||||
};
|
||||
drop(child.stdin.take());
|
||||
assert!(child.wait().unwrap().success(), "capture error: {:?}", result.as_ref().err());
|
||||
let export = result.unwrap();
|
||||
let capture = async {
|
||||
wait_for_top_test_child(&mut child, state.path()).await?;
|
||||
let mut request = disk_request(state.path());
|
||||
request.window_millis = 500;
|
||||
let export = super::request_local_top_rpc(state.path(), request.clone(), &CancellationToken::new()).await?;
|
||||
Ok::<_, LocalTraceCaptureError>((export, request))
|
||||
}
|
||||
.await;
|
||||
let status = stop_profile_test_child(&mut child, Duration::from_secs(10))
|
||||
.await
|
||||
.expect("top.rpc fixture must be reaped");
|
||||
assert!(status.success(), "fixture exit: {status}; capture error: {:?}", capture.as_ref().err());
|
||||
let (export, request) = capture.expect("top.rpc capture should succeed after fixture preparation");
|
||||
let mut zip = zip::ZipArchive::new(std::io::Cursor::new(&export.archive_bytes)).unwrap();
|
||||
let result: serde_json::Value = serde_json::from_reader(zip.by_name("result.json").unwrap()).unwrap();
|
||||
assert_eq!(result["toolId"], "top.rpc");
|
||||
@@ -2587,10 +2610,9 @@ mod tests {
|
||||
input_stop.cancel();
|
||||
});
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
prepare_top_test_provenance(std::path::Path::new(&state)).await;
|
||||
let runtime = spawn_local_trace_capture_runtime(std::path::Path::new(&state), &stop).unwrap();
|
||||
let emit = async {
|
||||
// Hashing the CI test executable must finish before timing subscriber readiness.
|
||||
super::super::job_delivery::executable_provenance().await.unwrap();
|
||||
tokio::time::timeout(Duration::from_secs(10), async {
|
||||
while telemetry_trace_subscriber_count() == 0 {
|
||||
tokio::task::yield_now().await;
|
||||
@@ -2623,9 +2645,7 @@ mod tests {
|
||||
use std::io::Read as _;
|
||||
let state = tempfile::tempdir().unwrap();
|
||||
std::fs::set_permissions(state.path(), std::fs::Permissions::from_mode(0o700)).unwrap();
|
||||
let mut request = disk_request(state.path());
|
||||
request.window_millis = 500;
|
||||
let mut child = std::process::Command::new(std::env::current_exe().unwrap())
|
||||
let mut child = tokio::process::Command::new(std::env::current_exe().unwrap())
|
||||
.args([
|
||||
"connect::diagnostics::trace_runtime::tests::local_top_api_service_child",
|
||||
"--exact",
|
||||
@@ -2633,22 +2653,22 @@ mod tests {
|
||||
])
|
||||
.env("RUSTFS_TEST_TOP_API_STATE", state.path())
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.kill_on_drop(true)
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let ready = tokio::time::timeout(Duration::from_secs(5), async {
|
||||
while !state.path().join(super::SOCKET_FILE).exists() {
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
})
|
||||
let capture = async {
|
||||
wait_for_top_test_child(&mut child, state.path()).await?;
|
||||
let mut request = disk_request(state.path());
|
||||
request.window_millis = 500;
|
||||
let export = super::request_local_top_api(state.path(), request.clone(), &CancellationToken::new()).await?;
|
||||
Ok::<_, LocalTraceCaptureError>((export, request))
|
||||
}
|
||||
.await;
|
||||
let result = if ready.is_ok() {
|
||||
super::request_local_top_api(state.path(), request.clone(), &CancellationToken::new()).await
|
||||
} else {
|
||||
Err(LocalTraceCaptureError::Protocol)
|
||||
};
|
||||
drop(child.stdin.take());
|
||||
assert!(child.wait().unwrap().success(), "capture error: {:?}", result.as_ref().err());
|
||||
let export = result.unwrap();
|
||||
let status = stop_profile_test_child(&mut child, Duration::from_secs(10))
|
||||
.await
|
||||
.expect("top.api fixture must be reaped");
|
||||
assert!(status.success(), "fixture exit: {status}; capture error: {:?}", capture.as_ref().err());
|
||||
let (export, request) = capture.expect("top.api capture should succeed after fixture preparation");
|
||||
let mut zip = zip::ZipArchive::new(std::io::Cursor::new(&export.archive_bytes)).unwrap();
|
||||
let result: serde_json::Value = serde_json::from_reader(zip.by_name("result.json").unwrap()).unwrap();
|
||||
assert_eq!(result["toolId"], "top.api");
|
||||
@@ -2686,6 +2706,7 @@ mod tests {
|
||||
});
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
assert!(rustfs_lock::get_global_lock_manager().as_fast_lock_manager().is_some());
|
||||
prepare_top_test_provenance(std::path::Path::new(&state)).await;
|
||||
let runtime = spawn_local_trace_capture_runtime(std::path::Path::new(&state), &stop).unwrap();
|
||||
stop.cancelled().await;
|
||||
runtime.shutdown().await;
|
||||
@@ -2698,8 +2719,7 @@ mod tests {
|
||||
use std::io::Read as _;
|
||||
let state = tempfile::tempdir().unwrap();
|
||||
std::fs::set_permissions(state.path(), std::fs::Permissions::from_mode(0o700)).unwrap();
|
||||
let request = disk_request(state.path());
|
||||
let mut child = std::process::Command::new(std::env::current_exe().unwrap())
|
||||
let mut child = tokio::process::Command::new(std::env::current_exe().unwrap())
|
||||
.args([
|
||||
"connect::diagnostics::trace_runtime::tests::local_top_locks_service_child",
|
||||
"--exact",
|
||||
@@ -2708,17 +2728,21 @@ mod tests {
|
||||
.env("RUSTFS_TEST_TOP_LOCKS_STATE", state.path())
|
||||
.env("RUSTFS_LOCK_ENABLED", "true")
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.kill_on_drop(true)
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let ready = wait_for_sealed_socket(state.path()).await;
|
||||
let result = if ready.is_ok() {
|
||||
super::request_local_top_locks(state.path(), request.clone(), &CancellationToken::new()).await
|
||||
} else {
|
||||
Err(LocalTraceCaptureError::Protocol)
|
||||
};
|
||||
drop(child.stdin.take());
|
||||
assert!(child.wait().unwrap().success());
|
||||
let export = result.unwrap();
|
||||
let capture = async {
|
||||
wait_for_top_test_child(&mut child, state.path()).await?;
|
||||
let request = disk_request(state.path());
|
||||
let export = super::request_local_top_locks(state.path(), request.clone(), &CancellationToken::new()).await?;
|
||||
Ok::<_, LocalTraceCaptureError>((export, request))
|
||||
}
|
||||
.await;
|
||||
let status = stop_profile_test_child(&mut child, Duration::from_secs(10))
|
||||
.await
|
||||
.expect("top.locks fixture must be reaped");
|
||||
assert!(status.success(), "fixture exit: {status}; capture error: {:?}", capture.as_ref().err());
|
||||
let (export, request) = capture.expect("top.locks capture should succeed after fixture preparation");
|
||||
let mut zip = zip::ZipArchive::new(std::io::Cursor::new(&export.archive_bytes)).unwrap();
|
||||
let result: serde_json::Value = serde_json::from_reader(zip.by_name("result.json").unwrap()).unwrap();
|
||||
assert_eq!(result["toolId"], "top.locks");
|
||||
@@ -2762,6 +2786,7 @@ mod tests {
|
||||
input_stop.cancel();
|
||||
});
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
prepare_top_test_provenance(&state).await;
|
||||
let runtime = spawn_local_trace_capture_runtime(&state, &stop).unwrap();
|
||||
stop.cancelled().await;
|
||||
runtime.shutdown().await;
|
||||
@@ -2775,8 +2800,7 @@ mod tests {
|
||||
use std::io::Read as _;
|
||||
let state = tempfile::tempdir().unwrap();
|
||||
std::fs::set_permissions(state.path(), std::fs::Permissions::from_mode(0o700)).unwrap();
|
||||
let request = disk_request(state.path());
|
||||
let mut child = std::process::Command::new(std::env::current_exe().unwrap())
|
||||
let mut child = tokio::process::Command::new(std::env::current_exe().unwrap())
|
||||
.args([
|
||||
"connect::diagnostics::trace_runtime::tests::local_top_disk_service_child",
|
||||
"--exact",
|
||||
@@ -2784,22 +2808,21 @@ mod tests {
|
||||
])
|
||||
.env("RUSTFS_TEST_TOP_DISK_STATE", state.path())
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.kill_on_drop(true)
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let ready = tokio::time::timeout(Duration::from_secs(5), async {
|
||||
while !state.path().join(super::SOCKET_FILE).exists() {
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
})
|
||||
let capture = async {
|
||||
wait_for_top_test_child(&mut child, state.path()).await?;
|
||||
let request = disk_request(state.path());
|
||||
let export = super::request_local_top_disk(state.path(), request.clone(), &CancellationToken::new()).await?;
|
||||
Ok::<_, LocalTraceCaptureError>((export, request))
|
||||
}
|
||||
.await;
|
||||
let result = if ready.is_ok() {
|
||||
super::request_local_top_disk(state.path(), request.clone(), &CancellationToken::new()).await
|
||||
} else {
|
||||
Err(LocalTraceCaptureError::Protocol)
|
||||
};
|
||||
drop(child.stdin.take());
|
||||
assert!(child.wait().unwrap().success());
|
||||
let export = result.unwrap();
|
||||
let status = stop_profile_test_child(&mut child, Duration::from_secs(10))
|
||||
.await
|
||||
.expect("top.disk fixture must be reaped");
|
||||
assert!(status.success(), "fixture exit: {status}; capture error: {:?}", capture.as_ref().err());
|
||||
let (export, request) = capture.expect("top.disk capture should succeed after fixture preparation");
|
||||
let mut zip = zip::ZipArchive::new(std::io::Cursor::new(&export.archive_bytes)).unwrap();
|
||||
let result: serde_json::Value = serde_json::from_reader(zip.by_name("result.json").unwrap()).unwrap();
|
||||
assert_eq!(result["outcome"], "SUCCEEDED");
|
||||
@@ -2901,7 +2924,6 @@ mod tests {
|
||||
.spawn()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
async fn wait_for_profile_child_marker(
|
||||
child: &mut tokio::process::Child,
|
||||
path: &std::path::Path,
|
||||
@@ -2925,7 +2947,6 @@ mod tests {
|
||||
.map_err(|_| std::io::Error::new(std::io::ErrorKind::TimedOut, "profile fixture readiness timed out"))?
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
async fn stop_profile_test_child(
|
||||
child: &mut tokio::process::Child,
|
||||
budget: Duration,
|
||||
|
||||
Reference in New Issue
Block a user