Files
lain bbb67a68ab feat(rpc): implement health check service and error handling
- Added `RpcError` enum for comprehensive error handling in RPC operations.
- Introduced `HealthReporter` and `HealthService` for managing service health statuses.
- Implemented health check and watch functionality in the health service.
- Created integration tests for health check service, covering various scenarios.
- Added unit tests for client options validation and stream functionality.
- Established logging infrastructure for terminal and registry components.
- Implemented logging lifecycle management and conflict resolution in tests.
2026-10-09 15:57:35 +08:00

71 lines
2.6 KiB
Rust

use std::collections::HashMap;
use std::process::Command;
use crate::{Config, logging};
#[test]
fn bridge_outputs_once_filters_and_flushes() {
if let Some(directory) = std::env::var_os("REGISTRY_LOG_TEST_CHILD") {
let directory = std::path::PathBuf::from(directory);
let config = Config::from_file(
&directory.join("absent.env"),
HashMap::from([("LOG_DIR".into(), directory.to_string_lossy().into_owned())]),
)
.unwrap();
logging::init_bridge().unwrap();
let guard = logging::init(&config).unwrap();
log::info!(target: "registry::log_test", "bridge-visible terminal_id=test-terminal");
log::debug!("bridge-hidden");
tracing::warn!(target: "registry::log_test", terminal_id = "test-terminal", "structured-visible");
let snapshot = directory.join("snapshot.bin");
std::fs::write(&snapshot, [0xff]).unwrap();
crate::storage::load(&snapshot).unwrap();
log::error!("last-record-before-flush");
drop(guard);
return;
}
let directory = tempfile::tempdir().unwrap();
let output = Command::new(std::env::current_exe().unwrap())
.args([
"--exact",
"unit_tests::logging::bridge_outputs_once_filters_and_flushes",
"--nocapture",
])
.env("REGISTRY_LOG_TEST_CHILD", directory.path())
.output()
.unwrap();
assert!(
output.status.success(),
"{}",
String::from_utf8_lossy(&output.stderr)
);
let console = String::from_utf8(output.stderr).unwrap();
let logs = std::fs::read_dir(directory.path())
.unwrap()
.map(|entry| entry.unwrap().path())
.filter(|path| path.extension().is_some_and(|extension| extension == "log"))
.collect::<Vec<_>>();
assert_eq!(logs.len(), 1);
let name = logs[0].file_name().unwrap().to_str().unwrap();
assert!(name.starts_with("registry."));
let date = &name["registry.".len()..name.len() - ".log".len()];
assert_eq!(date.len(), 10);
assert_eq!(&date[4..5], "-");
assert_eq!(&date[7..8], "-");
let file = std::fs::read_to_string(&logs[0]).unwrap();
for text in [&console, &file] {
for message in [
"bridge-visible",
"structured-visible",
"invalid registry snapshot",
"last-record-before-flush",
] {
assert_eq!(text.matches(message).count(), 1, "{text}");
}
assert!(!text.contains("bridge-hidden"));
assert!(text.contains("registry::log_test"));
assert!(text.contains("test-terminal"));
assert!(!text.contains('\u{1b}'));
}
}