Skip to content

Commit

Permalink
Another tokio-nursery test
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Jan 11, 2025
1 parent 733b8ef commit 04519bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/tokio-nursery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ futures-util = { version = "0.3.29", default-features = false, features = ["std"
tokio = { version = "1.29.0", features = ["rt", "sync"] }

[dev-dependencies]
tokio = { version = "1.29.0", features = ["macros", "rt"] }
tokio = { version = "1.29.0", features = ["macros", "rt", "time"] }

[lints]
workspace = true
21 changes: 21 additions & 0 deletions crates/tokio-nursery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ impl<T: 'static> Stream for NurseryStream<T> {
mod tests {
use super::*;
use futures_util::StreamExt;
use std::time::Duration;
use tokio::time::timeout;

#[test]
fn nursery_is_send() {
Expand Down Expand Up @@ -133,4 +135,23 @@ mod tests {
.await;
assert!(r.is_err());
}

#[tokio::test]
async fn no_close_until_drop() {
let (nursery, mut nursery_stream) = Nursery::new();
nursery.spawn(std::future::ready(1));
nursery.spawn(std::future::ready(2));
nursery.spawn(std::future::ready(3));
let mut values = Vec::new();
values.push(nursery_stream.next().await.unwrap());
values.push(nursery_stream.next().await.unwrap());
values.push(nursery_stream.next().await.unwrap());
values.sort_unstable();
assert_eq!(values, vec![1, 2, 3]);
let r = timeout(Duration::from_millis(100), nursery_stream.next()).await;
assert!(r.is_err());
drop(nursery);
let r = timeout(Duration::from_millis(100), nursery_stream.next()).await;
assert_eq!(r, Ok(None));
}
}

0 comments on commit 04519bd

Please sign in to comment.