Files
FlySimOperationSystem/registry/tests/unit/rpc.rs
T
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

58 lines
1.9 KiB
Rust

use futures_util::StreamExt;
use proto::control::TerminalInfo;
use crate::RegistryService;
use proto::rpc::stream::watch_stream as snapshots;
#[tokio::test]
async fn subscribers_receive_initial_and_changed_snapshots_then_close() {
let directory = tempfile::tempdir().unwrap();
let service = RegistryService::open(directory.path().join("terminals.bin"))
.await
.unwrap();
let mut first = Box::pin(snapshots(service.subscribe(), service.shutdown_receiver()));
let mut second = Box::pin(snapshots(service.subscribe(), service.shutdown_receiver()));
assert!(first.next().await.unwrap().unwrap().infos.is_empty());
assert!(second.next().await.unwrap().unwrap().infos.is_empty());
let info = TerminalInfo {
terminal_host: "localhost".into(),
terminal_port: 1234,
terminal_mac: "aa".into(),
..Default::default()
};
let id = service.register(info.clone()).await.unwrap();
assert!(first.next().await.unwrap().unwrap().infos.contains_key(&id));
assert!(
second
.next()
.await
.unwrap()
.unwrap()
.infos
.contains_key(&id)
);
service.register(info).await.unwrap();
assert!(
tokio::time::timeout(std::time::Duration::from_millis(20), first.next())
.await
.is_err()
);
service.deregister(id).await.unwrap();
assert!(first.next().await.unwrap().unwrap().infos.is_empty());
assert!(second.next().await.unwrap().unwrap().infos.is_empty());
service.shutdown().await;
assert!(first.next().await.is_none());
assert!(second.next().await.is_none());
assert!(
service
.register(TerminalInfo {
terminal_host: "localhost".into(),
terminal_port: 1234,
terminal_mac: "aa".into(),
..Default::default()
})
.await
.is_err()
);
}