Skip to content

Commit

Permalink
rt: test block_in_place followed by Pending (#2120)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo authored and carllerche committed Jan 24, 2020
1 parent f0bfebb commit a16c9a5
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions tokio/src/runtime/thread_pool/tests/loom_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));

Expand All @@ -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 {
Expand All @@ -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(|| {
Expand Down

0 comments on commit a16c9a5

Please sign in to comment.