From f25f12d57638a2928b3f738b3b1392d8773e276e Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Wed, 23 Sep 2020 14:35:10 -0400 Subject: rt: Allow concurrent `block_on`'s with basic_scheduler (#2804) --- tokio/tests/rt_common.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tokio/tests') diff --git a/tokio/tests/rt_common.rs b/tokio/tests/rt_common.rs index 35e2ea81..a8968be1 100644 --- a/tokio/tests/rt_common.rs +++ b/tokio/tests/rt_common.rs @@ -574,6 +574,38 @@ rt_test! { }); } + #[test] + fn always_active_parker() { + // This test it to show that we will always have + // an active parker even if we call block_on concurrently + + let rt = rt(); + let rt2 = rt.clone(); + + let (tx1, rx1) = oneshot::channel(); + let (tx2, rx2) = oneshot::channel(); + + let jh1 = thread::spawn(move || { + rt.block_on(async move { + rx2.await.unwrap(); + time::delay_for(Duration::from_millis(5)).await; + tx1.send(()).unwrap(); + }); + }); + + let jh2 = thread::spawn(move || { + rt2.block_on(async move { + tx2.send(()).unwrap(); + time::delay_for(Duration::from_millis(5)).await; + rx1.await.unwrap(); + time::delay_for(Duration::from_millis(5)).await; + }); + }); + + jh1.join().unwrap(); + jh2.join().unwrap(); + } + #[test] // IOCP requires setting the "max thread" concurrency value. The sane, // default, is to set this to the number of cores. Threads that poll I/O -- cgit v1.2.3