summaryrefslogtreecommitdiffstats
path: root/tokio/tests
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2020-08-23 08:45:52 -0700
committerGitHub <noreply@github.com>2020-08-23 17:45:52 +0200
commit9d58b70151d7dbb66139125520d383401396eb98 (patch)
tree3a5eed29fb88cad906a113207fc040ce56433bdc /tokio/tests
parentfde72bf047080287f92e24f025301e6b7325c341 (diff)
sync: move CancellationToken to tokio-util (#2721)
* sync: move CancellationToken to tokio-util The `CancellationToken` utility is only available with the `tokio_unstable` flag. This was done as the API is not final, but it adds friction for users. This patch moves `CancellationToken` to tokio-util where it is generally available. The tokio-util crate does not have any constraints on breaking change releases. * fix clippy * clippy again
Diffstat (limited to 'tokio/tests')
-rw-r--r--tokio/tests/async_send_sync.rs3
-rw-r--r--tokio/tests/sync_cancellation_token.rs220
2 files changed, 0 insertions, 223 deletions
diff --git a/tokio/tests/async_send_sync.rs b/tokio/tests/async_send_sync.rs
index afe053b1..45d11bd4 100644
--- a/tokio/tests/async_send_sync.rs
+++ b/tokio/tests/async_send_sync.rs
@@ -259,6 +259,3 @@ async_assert_fn!(tokio::time::timeout_at(Instant, BoxFutureSync<()>): Send & Syn
async_assert_fn!(tokio::time::timeout_at(Instant, BoxFutureSend<()>): Send & !Sync);
async_assert_fn!(tokio::time::timeout_at(Instant, BoxFuture<()>): !Send & !Sync);
async_assert_fn!(tokio::time::Interval::tick(_): Send & Sync);
-
-#[cfg(tokio_unstable)]
-assert_value!(tokio::sync::CancellationToken: Send & Sync);
diff --git a/tokio/tests/sync_cancellation_token.rs b/tokio/tests/sync_cancellation_token.rs
deleted file mode 100644
index de543c94..00000000
--- a/tokio/tests/sync_cancellation_token.rs
+++ /dev/null
@@ -1,220 +0,0 @@
-#![cfg(tokio_unstable)]
-
-use tokio::pin;
-use tokio::sync::CancellationToken;
-
-use core::future::Future;
-use core::task::{Context, Poll};
-use futures_test::task::new_count_waker;
-
-#[test]
-fn cancel_token() {
- let (waker, wake_counter) = new_count_waker();
- let token = CancellationToken::new();
- assert_eq!(false, token.is_cancelled());
-
- let wait_fut = token.cancelled();
- pin!(wait_fut);
-
- assert_eq!(
- Poll::Pending,
- wait_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
- assert_eq!(wake_counter, 0);
-
- let wait_fut_2 = token.cancelled();
- pin!(wait_fut_2);
-
- token.cancel();
- assert_eq!(wake_counter, 1);
- assert_eq!(true, token.is_cancelled());
-
- assert_eq!(
- Poll::Ready(()),
- wait_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
- assert_eq!(
- Poll::Ready(()),
- wait_fut_2.as_mut().poll(&mut Context::from_waker(&waker))
- );
-}
-
-#[test]
-fn cancel_child_token_through_parent() {
- let (waker, wake_counter) = new_count_waker();
- let token = CancellationToken::new();
-
- let child_token = token.child_token();
- assert!(!child_token.is_cancelled());
-
- let child_fut = child_token.cancelled();
- pin!(child_fut);
- let parent_fut = token.cancelled();
- pin!(parent_fut);
-
- assert_eq!(
- Poll::Pending,
- child_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
- assert_eq!(
- Poll::Pending,
- parent_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
- assert_eq!(wake_counter, 0);
-
- token.cancel();
- assert_eq!(wake_counter, 2);
- assert_eq!(true, token.is_cancelled());
- assert_eq!(true, child_token.is_cancelled());
-
- assert_eq!(
- Poll::Ready(()),
- child_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
- assert_eq!(
- Poll::Ready(()),
- parent_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
-}
-
-#[test]
-fn cancel_child_token_without_parent() {
- let (waker, wake_counter) = new_count_waker();
- let token = CancellationToken::new();
-
- let child_token_1 = token.child_token();
-
- let child_fut = child_token_1.cancelled();
- pin!(child_fut);
- let parent_fut = token.cancelled();
- pin!(parent_fut);
-
- assert_eq!(
- Poll::Pending,
- child_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
- assert_eq!(
- Poll::Pending,
- parent_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
- assert_eq!(wake_counter, 0);
-
- child_token_1.cancel();
- assert_eq!(wake_counter, 1);
- assert_eq!(false, token.is_cancelled());
- assert_eq!(true, child_token_1.is_cancelled());
-
- assert_eq!(
- Poll::Ready(()),
- child_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
- assert_eq!(
- Poll::Pending,
- parent_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
-
- let child_token_2 = token.child_token();
- let child_fut_2 = child_token_2.cancelled();
- pin!(child_fut_2);
-
- assert_eq!(
- Poll::Pending,
- child_fut_2.as_mut().poll(&mut Context::from_waker(&waker))
- );
- assert_eq!(
- Poll::Pending,
- parent_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
-
- token.cancel();
- assert_eq!(wake_counter, 3);
- assert_eq!(true, token.is_cancelled());
- assert_eq!(true, child_token_2.is_cancelled());
-
- assert_eq!(
- Poll::Ready(()),
- child_fut_2.as_mut().poll(&mut Context::from_waker(&waker))
- );
- assert_eq!(
- Poll::Ready(()),
- parent_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
-}
-
-#[test]
-fn create_child_token_after_parent_was_cancelled() {
- for drop_child_first in [true, false].iter().cloned() {
- let (waker, wake_counter) = new_count_waker();
- let token = CancellationToken::new();
- token.cancel();
-
- let child_token = token.child_token();
- assert!(child_token.is_cancelled());
-
- {
- let child_fut = child_token.cancelled();
- pin!(child_fut);
- let parent_fut = token.cancelled();
- pin!(parent_fut);
-
- assert_eq!(
- Poll::Ready(()),
- child_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
- assert_eq!(
- Poll::Ready(()),
- parent_fut.as_mut().poll(&mut Context::from_waker(&waker))
- );
- assert_eq!(wake_counter, 0);
-
- drop(child_fut);
- drop(parent_fut);
- }
-
- if drop_child_first {
- drop(child_token);
- drop(token);
- } else {
- drop(token);
- drop(child_token);
- }
- }
-}
-
-#[test]
-fn drop_multiple_child_tokens() {
- for drop_first_child_first in &[true, false] {
- let token = CancellationToken::new();
- let mut child_tokens = [None, None, None];
- for i in 0..child_tokens.len() {
- child_tokens[i] = Some(token.child_token());
- }
-
- assert!(!token.is_cancelled());
- assert!(!child_tokens[0].as_ref().unwrap().is_cancelled());
-
- for i in 0..child_tokens.len() {
- if *drop_first_child_first {
- child_tokens[i] = None;
- } else {
- child_tokens[child_tokens.len() - 1 - i] = None;
- }
- assert!(!token.is_cancelled());
- }
-
- drop(token);
- }
-}
-
-#[test]
-fn drop_parent_before_child_tokens() {
- let token = CancellationToken::new();
- let child1 = token.child_token();
- let child2 = token.child_token();
-
- drop(token);
- assert!(!child1.is_cancelled());
-
- drop(child1);
- drop(child2);
-}