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.
This commit is contained in:
2026-10-09 15:57:35 +08:00
parent 7f331565c7
commit bbb67a68ab
65 changed files with 3313 additions and 695 deletions
+68
View File
@@ -0,0 +1,68 @@
use crate::rpc::client::{RpcChannel, RpcClientOptions, RpcEndpoint};
use std::time::Duration;
#[test]
fn validates_endpoints_and_preserves_compatibility_exports() {
let defaults = RpcClientOptions::default();
assert_eq!(defaults.connect_timeout, Duration::from_secs(3));
assert!(defaults.request_timeout.is_none());
for host in ["localhost", "127.0.0.1", "::1", "[::1]"] {
let endpoint = RpcEndpoint::from_host_port(host, 1234).unwrap();
assert_eq!(endpoint.uri().port_u16(), Some(1234));
assert_eq!(
RpcEndpoint::from_uri(endpoint.uri().clone()).unwrap(),
endpoint
);
}
for host in [
"",
" foo ",
"user@host",
"host/path",
"host?query",
"host:99",
"[foo]",
] {
assert!(RpcEndpoint::from_host_port(host, 1234).is_err());
}
assert!(RpcEndpoint::from_host_port("localhost", 0).is_err());
for uri in [
"https://localhost:99/",
"http://localhost/",
"http://localhost:0/",
"http://localhost:65536/",
"http://localhost:99/path",
"http://localhost:99/?q=1",
"http://user@localhost:99/",
] {
assert!(
RpcEndpoint::from_uri(uri.parse().unwrap()).is_err(),
"{uri}"
);
}
let _: crate::control::TerminalInfo = crate::proto::control::TerminalInfo::default();
}
#[tokio::test]
async fn invalid_options_fail_before_connecting() {
let endpoint = RpcEndpoint::from_host_port("localhost", 1234).unwrap();
for options in [
RpcClientOptions {
connect_timeout: Duration::ZERO,
..Default::default()
},
RpcClientOptions {
request_timeout: Some(Duration::ZERO),
..Default::default()
},
RpcClientOptions {
buffer_capacity: 0,
..Default::default()
},
] {
assert!(matches!(
RpcChannel::connect(&endpoint, options).await,
Err(crate::rpc::RpcError::InvalidOptions(_))
));
}
}