aboutsummaryrefslogtreecommitdiff
path: root/src/sync/tests/loom_cancellation_token.rs
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2020-10-23 09:39:31 -0700
committerJoel Galenson <jgalenson@google.com>2020-10-23 09:52:09 -0700
commitd5495b03381a3ebe0805db353d198b285b535b5c (patch)
tree778b8524d15fca8b73db0253ee0e1919d0848bb6 /src/sync/tests/loom_cancellation_token.rs
parentba45c5bedf31df8562364c61d3dfb5262f10642e (diff)
downloadtokio-d5495b03381a3ebe0805db353d198b285b535b5c.tar.gz
Update to tokio-0.3.1 and add new features
Test: Build Change-Id: I5b5b9b386a21982a019653d0cf0bd3afc505cfac
Diffstat (limited to 'src/sync/tests/loom_cancellation_token.rs')
-rw-r--r--src/sync/tests/loom_cancellation_token.rs155
1 files changed, 0 insertions, 155 deletions
diff --git a/src/sync/tests/loom_cancellation_token.rs b/src/sync/tests/loom_cancellation_token.rs
deleted file mode 100644
index e9c9f3d..0000000
--- a/src/sync/tests/loom_cancellation_token.rs
+++ /dev/null
@@ -1,155 +0,0 @@
-use crate::sync::CancellationToken;
-
-use loom::{future::block_on, thread};
-use tokio_test::assert_ok;
-
-#[test]
-fn cancel_token() {
- loom::model(|| {
- let token = CancellationToken::new();
- let token1 = token.clone();
-
- let th1 = thread::spawn(move || {
- block_on(async {
- token1.cancelled().await;
- });
- });
-
- let th2 = thread::spawn(move || {
- token.cancel();
- });
-
- assert_ok!(th1.join());
- assert_ok!(th2.join());
- });
-}
-
-#[test]
-fn cancel_with_child() {
- loom::model(|| {
- let token = CancellationToken::new();
- let token1 = token.clone();
- let token2 = token.clone();
- let child_token = token.child_token();
-
- let th1 = thread::spawn(move || {
- block_on(async {
- token1.cancelled().await;
- });
- });
-
- let th2 = thread::spawn(move || {
- token2.cancel();
- });
-
- let th3 = thread::spawn(move || {
- block_on(async {
- child_token.cancelled().await;
- });
- });
-
- assert_ok!(th1.join());
- assert_ok!(th2.join());
- assert_ok!(th3.join());
- });
-}
-
-#[test]
-fn drop_token_no_child() {
- loom::model(|| {
- let token = CancellationToken::new();
- let token1 = token.clone();
- let token2 = token.clone();
-
- let th1 = thread::spawn(move || {
- drop(token1);
- });
-
- let th2 = thread::spawn(move || {
- drop(token2);
- });
-
- let th3 = thread::spawn(move || {
- drop(token);
- });
-
- assert_ok!(th1.join());
- assert_ok!(th2.join());
- assert_ok!(th3.join());
- });
-}
-
-#[test]
-fn drop_token_with_childs() {
- loom::model(|| {
- let token1 = CancellationToken::new();
- let child_token1 = token1.child_token();
- let child_token2 = token1.child_token();
-
- let th1 = thread::spawn(move || {
- drop(token1);
- });
-
- let th2 = thread::spawn(move || {
- drop(child_token1);
- });
-
- let th3 = thread::spawn(move || {
- drop(child_token2);
- });
-
- assert_ok!(th1.join());
- assert_ok!(th2.join());
- assert_ok!(th3.join());
- });
-}
-
-#[test]
-fn drop_and_cancel_token() {
- loom::model(|| {
- let token1 = CancellationToken::new();
- let token2 = token1.clone();
- let child_token = token1.child_token();
-
- let th1 = thread::spawn(move || {
- drop(token1);
- });
-
- let th2 = thread::spawn(move || {
- token2.cancel();
- });
-
- let th3 = thread::spawn(move || {
- drop(child_token);
- });
-
- assert_ok!(th1.join());
- assert_ok!(th2.join());
- assert_ok!(th3.join());
- });
-}
-
-#[test]
-fn cancel_parent_and_child() {
- loom::model(|| {
- let token1 = CancellationToken::new();
- let token2 = token1.clone();
- let child_token = token1.child_token();
-
- let th1 = thread::spawn(move || {
- drop(token1);
- });
-
- let th2 = thread::spawn(move || {
- token2.cancel();
- });
-
- let th3 = thread::spawn(move || {
- child_token.cancel();
- });
-
- assert_ok!(th1.join());
- assert_ok!(th2.join());
- assert_ok!(th3.join());
- });
-}