From 89a87d58367ffa97ed4651bf0f5cb06e06d9a2bf Mon Sep 17 00:00:00 2001 From: Noah Kennedy Date: Wed, 21 Sep 2022 11:31:12 -0500 Subject: [PATCH] checkpoint --- tokio/src/task/local.rs | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tokio/src/task/local.rs b/tokio/src/task/local.rs index 4ad80649a..48a8817b7 100644 --- a/tokio/src/task/local.rs +++ b/tokio/src/task/local.rs @@ -923,3 +923,48 @@ impl task::Schedule for Arc { } } } + +#[cfg(test)] +mod tests { + use super::*; + + use crate::sync::oneshot; + use crate::time::sleep; + use std::time::Duration; + + #[test] + fn test_local() { + let rt = crate::runtime::Builder::new_current_thread() + .enable_all() + .build() + .expect("failed to create runtime"); + + let local = LocalSet::new(); + // Comment this and the program would exit as usual. + let _guard = local.enter(); + + let (tx, rx) = oneshot::channel(); + + local.block_on(&rt, async move { + println!("Blocking"); + + spawn_local(async move { + println!("Started"); + sleep(Duration::ZERO).await; + + println!("Yielded"); + + tx.send(()).expect("failed to send"); + + println!("Sent"); + }); + assert_eq!( + crate::time::timeout(Duration::from_secs(1), rx) + .await + .unwrap(), + Ok(()) + ); + println!("Finished"); + }); + } +}