From a78006577ebfa95eaa523a657f2763bcd7aeac3b Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Thu, 30 Mar 2023 10:29:21 +0200 Subject: Upgrade tokio-stream to 0.1.12 This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update rust/crates/tokio-stream For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md Test: TreeHugger Change-Id: I7a8393fe09a15ef4e6490ad01d772494a1a6e1b9 --- tests/watch.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'tests/watch.rs') diff --git a/tests/watch.rs b/tests/watch.rs index a56254e..3a39aaf 100644 --- a/tests/watch.rs +++ b/tests/watch.rs @@ -3,9 +3,11 @@ use tokio::sync::watch; use tokio_stream::wrappers::WatchStream; use tokio_stream::StreamExt; +use tokio_test::assert_pending; +use tokio_test::task::spawn; #[tokio::test] -async fn message_not_twice() { +async fn watch_stream_message_not_twice() { let (tx, rx) = watch::channel("hello"); let mut counter = 0; @@ -27,3 +29,29 @@ async fn message_not_twice() { drop(tx); task.await.unwrap(); } + +#[tokio::test] +async fn watch_stream_from_rx() { + let (tx, rx) = watch::channel("hello"); + + let mut stream = WatchStream::from(rx); + + assert_eq!(stream.next().await.unwrap(), "hello"); + + tx.send("bye").unwrap(); + + assert_eq!(stream.next().await.unwrap(), "bye"); +} + +#[tokio::test] +async fn watch_stream_from_changes() { + let (tx, rx) = watch::channel("hello"); + + let mut stream = WatchStream::from_changes(rx); + + assert_pending!(spawn(&mut stream).poll_next()); + + tx.send("bye").unwrap(); + + assert_eq!(stream.next().await.unwrap(), "bye"); +} -- cgit v1.2.3