Files
FlySimOperationSystem/registry/tests/unit/rpc.rs
T
lain 7f331565c7 Add terminal service implementation and integration tests
- Introduced terminal.h header file defining the terminal service API.
- Implemented integration tests for terminal service registration and health checks.
- Added unit tests for FFI layer, health checks, and terminal service functionality.
- Created a mock center for testing terminal registration and deregistration.
- Ensured proper error handling and response validation in tests.
2026-09-20 10:55:38 +08:00

58 lines
1.9 KiB
Rust

use futures_util::StreamExt;
use proto::proto::control::TerminalInfo;
use crate::RegistryService;
use crate::rpc::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()
);
}