summaryrefslogtreecommitdiffstats
path: root/tokio/tests/task_local_set.rs
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2020-03-05 10:31:37 -0800
committerGitHub <noreply@github.com>2020-03-05 10:31:37 -0800
commita78b1c65ccfb9692ca5d3ed8ddde934f40091d83 (patch)
treec88e547d6913b204f590aea54dc03328ee3cb094 /tokio/tests/task_local_set.rs
parent5ede2e4d6b2f732e83e33f9693682dffc6c9f5b0 (diff)
rt: cleanup and simplify scheduler (scheduler v2.5) (#2273)
A refactor of the scheduler internals focusing on simplifying and reducing unsafety. There are no fundamental logic changes. * The state transitions of the core task component are refined and reduced. * `basic_scheduler` has most unsafety removed. * `local_set` has most unsafety removed. * `threaded_scheduler` limits most unsafety to its queue implementation.
Diffstat (limited to 'tokio/tests/task_local_set.rs')
-rw-r--r--tokio/tests/task_local_set.rs33
1 files changed, 19 insertions, 14 deletions
diff --git a/tokio/tests/task_local_set.rs b/tokio/tests/task_local_set.rs
index 42bd4607..1a10fefa 100644
--- a/tokio/tests/task_local_set.rs
+++ b/tokio/tests/task_local_set.rs
@@ -1,20 +1,15 @@
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
-use std::{
- cell::Cell,
- sync::atomic::{
- AtomicBool, AtomicUsize,
- Ordering::{self, SeqCst},
- },
- time::Duration,
-};
-use tokio::{
- runtime::{self, Runtime},
- sync::{mpsc, oneshot},
- task::{self, LocalSet},
- time,
-};
+use tokio::runtime::{self, Runtime};
+use tokio::sync::{mpsc, oneshot};
+use tokio::task::{self, LocalSet};
+use tokio::time;
+
+use std::cell::Cell;
+use std::sync::atomic::Ordering::{self, SeqCst};
+use std::sync::atomic::{AtomicBool, AtomicUsize};
+use std::time::Duration;
#[tokio::test(basic_scheduler)]
async fn local_basic_scheduler() {
@@ -285,15 +280,23 @@ fn join_local_future_elsewhere() {
join2.await.unwrap()
});
}
+
#[test]
fn drop_cancels_tasks() {
+ use std::rc::Rc;
+
// This test reproduces issue #1842
let mut rt = rt();
+ let rc1 = Rc::new(());
+ let rc2 = rc1.clone();
let (started_tx, started_rx) = oneshot::channel();
let local = LocalSet::new();
local.spawn_local(async move {
+ // Move this in
+ let _rc2 = rc2;
+
started_tx.send(()).unwrap();
loop {
time::delay_for(Duration::from_secs(3600)).await;
@@ -305,6 +308,8 @@ fn drop_cancels_tasks() {
});
drop(local);
drop(rt);
+
+ assert_eq!(1, Rc::strong_count(&rc1));
}
#[test]