From 091a709dcc3746a4a5e09479b5230c7bfdd73f79 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Wed, 15 Jan 2020 18:51:36 -0500 Subject: [PATCH] Test block_in_place followed by Pending --- .../runtime/thread_pool/tests/loom_pool.rs | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/tokio/src/runtime/thread_pool/tests/loom_pool.rs b/tokio/src/runtime/thread_pool/tests/loom_pool.rs index 0394db16696..3151eaa6242 100644 --- a/tokio/src/runtime/thread_pool/tests/loom_pool.rs +++ b/tokio/src/runtime/thread_pool/tests/loom_pool.rs @@ -41,16 +41,18 @@ fn pool_multi_spawn() { }); } -#[test] -fn only_blocking() { - loom::model(|| { +fn only_blocking_inner(first_pending: bool) { + loom::model(move || { let pool = mk_pool(1); let (block_tx, block_rx) = oneshot::channel(); pool.spawn(async move { crate::task::block_in_place(move || { block_tx.send(()); - }) + }); + if first_pending { + yield_once().await + } }); block_rx.recv(); @@ -59,9 +61,18 @@ fn only_blocking() { } #[test] -fn blocking_and_regular() { +fn only_blocking() { + only_blocking_inner(false) +} + +#[test] +fn only_blocking_with_pending() { + only_blocking_inner(true) +} + +fn blocking_and_regular_inner(first_pending: bool) { const NUM: usize = 3; - loom::model(|| { + loom::model(move || { let pool = mk_pool(1); let cnt = Arc::new(AtomicUsize::new(0)); @@ -72,7 +83,10 @@ fn blocking_and_regular() { pool.spawn(async move { crate::task::block_in_place(move || { block_tx.send(()); - }) + }); + if first_pending { + yield_once().await + } }); for _ in 0..NUM { @@ -93,6 +107,16 @@ fn blocking_and_regular() { }); } +#[test] +fn blocking_and_regular() { + blocking_and_regular_inner(false); +} + +#[test] +fn blocking_and_regular_with_pending() { + blocking_and_regular_inner(true); +} + #[test] fn pool_multi_notify() { loom::model(|| {