summaryrefslogtreecommitdiff
path: root/tests/watch.rs
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 05:06:53 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 05:06:53 +0000
commit1bc36c29c5f772e04bb465e9d54c0af228b2886f (patch)
treea1abb0fc9b7e3d95c763e59b97e3a01b6101b5cf /tests/watch.rs
parent7c0c931ff070847d4b4a5effecda9ad760a2d15b (diff)
parent6615c451a218ef4be8eb3bac1a9b81ba8c25f6f5 (diff)
downloadtokio-stream-1bc36c29c5f772e04bb465e9d54c0af228b2886f.tar.gz
Snap for 10453563 from 6615c451a218ef4be8eb3bac1a9b81ba8c25f6f5 to mainline-neuralnetworks-releaseaml_neu_341510000aml_neu_341010080aml_neu_341010000
Change-Id: I2c50b2a8616e17c46ed719634517d98d8b702c30
Diffstat (limited to 'tests/watch.rs')
-rw-r--r--tests/watch.rs30
1 files changed, 29 insertions, 1 deletions
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");
+}