From 04519bd552f3f8709aff9b63f19407cada1fc84f Mon Sep 17 00:00:00 2001 From: "John T. Wodder II" Date: Sat, 11 Jan 2025 07:48:34 -0500 Subject: [PATCH] Another tokio-nursery test --- crates/tokio-nursery/Cargo.toml | 2 +- crates/tokio-nursery/src/lib.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/tokio-nursery/Cargo.toml b/crates/tokio-nursery/Cargo.toml index ff60ed3..d2984d2 100644 --- a/crates/tokio-nursery/Cargo.toml +++ b/crates/tokio-nursery/Cargo.toml @@ -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 diff --git a/crates/tokio-nursery/src/lib.rs b/crates/tokio-nursery/src/lib.rs index ba17fc7..295affc 100644 --- a/crates/tokio-nursery/src/lib.rs +++ b/crates/tokio-nursery/src/lib.rs @@ -82,6 +82,8 @@ impl Stream for NurseryStream { mod tests { use super::*; use futures_util::StreamExt; + use std::time::Duration; + use tokio::time::timeout; #[test] fn nursery_is_send() { @@ -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)); + } }