mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Upgrade tokio to 1.10 (#9575)
* Upgrade tokio to 1.10 * Fix test runner * Try fix it * Update Cargo.lock * Review feedback * ahhhh * FML * FMT * Fix tests
This commit is contained in:
@@ -311,7 +311,13 @@ impl TaskManager {
|
||||
Box::pin(async move {
|
||||
join_all(children_shutdowns).await;
|
||||
completion_future.await;
|
||||
drop(keep_alive);
|
||||
|
||||
// The keep_alive stuff is holding references to some RPC handles etc. These
|
||||
// RPC handles spawn their own tokio stuff and that doesn't like to be closed in an
|
||||
// async context. So, we move the deletion to some other thread.
|
||||
std::thread::spawn(move || {
|
||||
let _ = keep_alive;
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,12 @@ impl DropTester {
|
||||
*self.0.lock() += 1;
|
||||
DropTesterRef(self.clone())
|
||||
}
|
||||
|
||||
fn wait_on_drop(&self) {
|
||||
while *self != 0 {
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<usize> for DropTester {
|
||||
@@ -65,7 +71,7 @@ fn ensure_drop_tester_working() {
|
||||
|
||||
async fn run_background_task(_keep_alive: impl Any) {
|
||||
loop {
|
||||
tokio::time::delay_for(Duration::from_secs(1)).await;
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +80,7 @@ async fn run_background_task_blocking(duration: Duration, _keep_alive: impl Any)
|
||||
// block for X sec (not interruptible)
|
||||
std::thread::sleep(duration);
|
||||
// await for 1 sec (interruptible)
|
||||
tokio::time::delay_for(Duration::from_secs(1)).await;
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +90,7 @@ fn new_task_manager(task_executor: TaskExecutor) -> TaskManager {
|
||||
|
||||
#[test]
|
||||
fn ensure_tasks_are_awaited_on_shutdown() {
|
||||
let mut runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let handle = runtime.handle().clone();
|
||||
let task_executor: TaskExecutor = (move |future, _| handle.spawn(future).map(|_| ())).into();
|
||||
|
||||
@@ -95,15 +101,15 @@ fn ensure_tasks_are_awaited_on_shutdown() {
|
||||
spawn_handle.spawn("task2", run_background_task(drop_tester.new_ref()));
|
||||
assert_eq!(drop_tester, 2);
|
||||
// allow the tasks to even start
|
||||
runtime.block_on(async { tokio::time::delay_for(Duration::from_secs(1)).await });
|
||||
runtime.block_on(async { tokio::time::sleep(Duration::from_secs(1)).await });
|
||||
assert_eq!(drop_tester, 2);
|
||||
runtime.block_on(task_manager.clean_shutdown());
|
||||
assert_eq!(drop_tester, 0);
|
||||
drop_tester.wait_on_drop();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_keep_alive_during_shutdown() {
|
||||
let mut runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let handle = runtime.handle().clone();
|
||||
let task_executor: TaskExecutor = (move |future, _| handle.spawn(future).map(|_| ())).into();
|
||||
|
||||
@@ -114,15 +120,15 @@ fn ensure_keep_alive_during_shutdown() {
|
||||
spawn_handle.spawn("task1", run_background_task(()));
|
||||
assert_eq!(drop_tester, 1);
|
||||
// allow the tasks to even start
|
||||
runtime.block_on(async { tokio::time::delay_for(Duration::from_secs(1)).await });
|
||||
runtime.block_on(async { tokio::time::sleep(Duration::from_secs(1)).await });
|
||||
assert_eq!(drop_tester, 1);
|
||||
runtime.block_on(task_manager.clean_shutdown());
|
||||
assert_eq!(drop_tester, 0);
|
||||
drop_tester.wait_on_drop();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_blocking_futures_are_awaited_on_shutdown() {
|
||||
let mut runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let handle = runtime.handle().clone();
|
||||
let task_executor: TaskExecutor = (move |future, _| handle.spawn(future).map(|_| ())).into();
|
||||
|
||||
@@ -139,7 +145,7 @@ fn ensure_blocking_futures_are_awaited_on_shutdown() {
|
||||
);
|
||||
assert_eq!(drop_tester, 2);
|
||||
// allow the tasks to even start
|
||||
runtime.block_on(async { tokio::time::delay_for(Duration::from_secs(1)).await });
|
||||
runtime.block_on(async { tokio::time::sleep(Duration::from_secs(1)).await });
|
||||
assert_eq!(drop_tester, 2);
|
||||
runtime.block_on(task_manager.clean_shutdown());
|
||||
assert_eq!(drop_tester, 0);
|
||||
@@ -147,7 +153,7 @@ fn ensure_blocking_futures_are_awaited_on_shutdown() {
|
||||
|
||||
#[test]
|
||||
fn ensure_no_task_can_be_spawn_after_terminate() {
|
||||
let mut runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let handle = runtime.handle().clone();
|
||||
let task_executor: TaskExecutor = (move |future, _| handle.spawn(future).map(|_| ())).into();
|
||||
|
||||
@@ -158,17 +164,17 @@ fn ensure_no_task_can_be_spawn_after_terminate() {
|
||||
spawn_handle.spawn("task2", run_background_task(drop_tester.new_ref()));
|
||||
assert_eq!(drop_tester, 2);
|
||||
// allow the tasks to even start
|
||||
runtime.block_on(async { tokio::time::delay_for(Duration::from_secs(1)).await });
|
||||
runtime.block_on(async { tokio::time::sleep(Duration::from_secs(1)).await });
|
||||
assert_eq!(drop_tester, 2);
|
||||
task_manager.terminate();
|
||||
spawn_handle.spawn("task3", run_background_task(drop_tester.new_ref()));
|
||||
runtime.block_on(task_manager.clean_shutdown());
|
||||
assert_eq!(drop_tester, 0);
|
||||
drop_tester.wait_on_drop();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_task_manager_future_ends_when_task_manager_terminated() {
|
||||
let mut runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let handle = runtime.handle().clone();
|
||||
let task_executor: TaskExecutor = (move |future, _| handle.spawn(future).map(|_| ())).into();
|
||||
|
||||
@@ -179,7 +185,7 @@ fn ensure_task_manager_future_ends_when_task_manager_terminated() {
|
||||
spawn_handle.spawn("task2", run_background_task(drop_tester.new_ref()));
|
||||
assert_eq!(drop_tester, 2);
|
||||
// allow the tasks to even start
|
||||
runtime.block_on(async { tokio::time::delay_for(Duration::from_secs(1)).await });
|
||||
runtime.block_on(async { tokio::time::sleep(Duration::from_secs(1)).await });
|
||||
assert_eq!(drop_tester, 2);
|
||||
task_manager.terminate();
|
||||
runtime.block_on(task_manager.future()).expect("future has ended without error");
|
||||
@@ -189,7 +195,7 @@ fn ensure_task_manager_future_ends_when_task_manager_terminated() {
|
||||
|
||||
#[test]
|
||||
fn ensure_task_manager_future_ends_with_error_when_essential_task_fails() {
|
||||
let mut runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let handle = runtime.handle().clone();
|
||||
let task_executor: TaskExecutor = (move |future, _| handle.spawn(future).map(|_| ())).into();
|
||||
|
||||
@@ -201,7 +207,7 @@ fn ensure_task_manager_future_ends_with_error_when_essential_task_fails() {
|
||||
spawn_handle.spawn("task2", run_background_task(drop_tester.new_ref()));
|
||||
assert_eq!(drop_tester, 2);
|
||||
// allow the tasks to even start
|
||||
runtime.block_on(async { tokio::time::delay_for(Duration::from_secs(1)).await });
|
||||
runtime.block_on(async { tokio::time::sleep(Duration::from_secs(1)).await });
|
||||
assert_eq!(drop_tester, 2);
|
||||
spawn_essential_handle.spawn("task3", async { panic!("task failed") });
|
||||
runtime
|
||||
@@ -209,12 +215,12 @@ fn ensure_task_manager_future_ends_with_error_when_essential_task_fails() {
|
||||
.expect_err("future()'s Result must be Err");
|
||||
assert_eq!(drop_tester, 2);
|
||||
runtime.block_on(task_manager.clean_shutdown());
|
||||
assert_eq!(drop_tester, 0);
|
||||
drop_tester.wait_on_drop();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_children_tasks_ends_when_task_manager_terminated() {
|
||||
let mut runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let handle = runtime.handle().clone();
|
||||
let task_executor: TaskExecutor = (move |future, _| handle.spawn(future).map(|_| ())).into();
|
||||
|
||||
@@ -233,17 +239,17 @@ fn ensure_children_tasks_ends_when_task_manager_terminated() {
|
||||
spawn_handle_child_2.spawn("task4", run_background_task(drop_tester.new_ref()));
|
||||
assert_eq!(drop_tester, 4);
|
||||
// allow the tasks to even start
|
||||
runtime.block_on(async { tokio::time::delay_for(Duration::from_secs(1)).await });
|
||||
runtime.block_on(async { tokio::time::sleep(Duration::from_secs(1)).await });
|
||||
assert_eq!(drop_tester, 4);
|
||||
task_manager.terminate();
|
||||
runtime.block_on(task_manager.future()).expect("future has ended without error");
|
||||
runtime.block_on(task_manager.clean_shutdown());
|
||||
assert_eq!(drop_tester, 0);
|
||||
drop_tester.wait_on_drop();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_task_manager_future_ends_with_error_when_childs_essential_task_fails() {
|
||||
let mut runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let handle = runtime.handle().clone();
|
||||
let task_executor: TaskExecutor = (move |future, _| handle.spawn(future).map(|_| ())).into();
|
||||
|
||||
@@ -263,7 +269,7 @@ fn ensure_task_manager_future_ends_with_error_when_childs_essential_task_fails()
|
||||
spawn_handle_child_2.spawn("task4", run_background_task(drop_tester.new_ref()));
|
||||
assert_eq!(drop_tester, 4);
|
||||
// allow the tasks to even start
|
||||
runtime.block_on(async { tokio::time::delay_for(Duration::from_secs(1)).await });
|
||||
runtime.block_on(async { tokio::time::sleep(Duration::from_secs(1)).await });
|
||||
assert_eq!(drop_tester, 4);
|
||||
spawn_essential_handle_child_1.spawn("task5", async { panic!("task failed") });
|
||||
runtime
|
||||
@@ -271,12 +277,12 @@ fn ensure_task_manager_future_ends_with_error_when_childs_essential_task_fails()
|
||||
.expect_err("future()'s Result must be Err");
|
||||
assert_eq!(drop_tester, 4);
|
||||
runtime.block_on(task_manager.clean_shutdown());
|
||||
assert_eq!(drop_tester, 0);
|
||||
drop_tester.wait_on_drop();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_task_manager_future_continues_when_childs_not_essential_task_fails() {
|
||||
let mut runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let handle = runtime.handle().clone();
|
||||
let task_executor: TaskExecutor = (move |future, _| handle.spawn(future).map(|_| ())).into();
|
||||
|
||||
@@ -295,12 +301,12 @@ fn ensure_task_manager_future_continues_when_childs_not_essential_task_fails() {
|
||||
spawn_handle_child_2.spawn("task4", run_background_task(drop_tester.new_ref()));
|
||||
assert_eq!(drop_tester, 4);
|
||||
// allow the tasks to even start
|
||||
runtime.block_on(async { tokio::time::delay_for(Duration::from_secs(1)).await });
|
||||
runtime.block_on(async { tokio::time::sleep(Duration::from_secs(1)).await });
|
||||
assert_eq!(drop_tester, 4);
|
||||
spawn_handle_child_1.spawn("task5", async { panic!("task failed") });
|
||||
runtime.block_on(async {
|
||||
let t1 = task_manager.future().fuse();
|
||||
let t2 = tokio::time::delay_for(Duration::from_secs(3)).fuse();
|
||||
let t2 = tokio::time::sleep(Duration::from_secs(3)).fuse();
|
||||
|
||||
pin_mut!(t1, t2);
|
||||
|
||||
@@ -311,5 +317,5 @@ fn ensure_task_manager_future_continues_when_childs_not_essential_task_fails() {
|
||||
});
|
||||
assert_eq!(drop_tester, 4);
|
||||
runtime.block_on(task_manager.clean_shutdown());
|
||||
assert_eq!(drop_tester, 0);
|
||||
drop_tester.wait_on_drop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user