- 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.
43 lines
1.5 KiB
Rust
43 lines
1.5 KiB
Rust
use crate::rpc::stream::watch_stream;
|
|
use futures_util::StreamExt;
|
|
use tokio::sync::watch;
|
|
|
|
#[tokio::test]
|
|
async fn initial_latest_multiple_subscribers_and_shutdown() {
|
|
let (sender, receiver) = watch::channel(0);
|
|
let (stop, shutdown) = watch::channel(false);
|
|
let mut first = Box::pin(watch_stream(receiver.clone(), shutdown.clone()));
|
|
let mut second = Box::pin(watch_stream(receiver, shutdown.clone()));
|
|
sender.send_replace(1);
|
|
assert_eq!(first.next().await.unwrap().unwrap(), 1);
|
|
assert_eq!(second.next().await.unwrap().unwrap(), 1);
|
|
sender.send_replace(2);
|
|
sender.send_replace(3);
|
|
assert_eq!(first.next().await.unwrap().unwrap(), 3);
|
|
assert_eq!(second.next().await.unwrap().unwrap(), 3);
|
|
stop.send_replace(true);
|
|
assert!(first.next().await.is_none());
|
|
assert!(second.next().await.is_none());
|
|
assert!(
|
|
Box::pin(watch_stream(sender.subscribe(), shutdown))
|
|
.next()
|
|
.await
|
|
.is_none()
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn channel_closure_ends_stream() {
|
|
let (sender, receiver) = watch::channel(0);
|
|
let (stop, shutdown) = watch::channel(false);
|
|
let mut stream = Box::pin(watch_stream(receiver, shutdown));
|
|
stream.next().await.unwrap().unwrap();
|
|
drop(sender);
|
|
assert!(stream.next().await.is_none());
|
|
let (sender, receiver) = watch::channel(0);
|
|
let mut stream = Box::pin(watch_stream(receiver, stop.subscribe()));
|
|
drop(stop);
|
|
assert!(stream.next().await.is_none());
|
|
drop(sender);
|
|
}
|