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:
Bastian Köcher
2021-08-24 16:31:19 +02:00
committed by GitHub
parent d722c44248
commit f92e5c5e65
24 changed files with 143 additions and 378 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
futures = "0.3.16"
substrate-test-utils-derive = { version = "0.10.0-dev", path = "./derive" }
tokio = { version = "0.2.13", features = ["macros", "rt-core", "time"] }
tokio = { version = "1.10", features = ["macros", "time"] }
[dev-dependencies]
sc-service = { version = "0.10.0-dev", path = "../client/service" }
+1
View File
@@ -12,6 +12,7 @@ description = "Substrate test utilities macros"
quote = "1.0.6"
syn = { version = "1.0.58", features = ["full"] }
proc-macro-crate = "1.0.0"
proc-macro2 = "1.0.28"
[lib]
proc-macro = true
+8 -23
View File
@@ -22,19 +22,14 @@ use quote::quote;
#[proc_macro_attribute]
pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
impl_test(args, item)
}
fn impl_test(args: TokenStream, item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::ItemFn);
let args = syn::parse_macro_input!(args as syn::AttributeArgs);
parse_knobs(input, args).unwrap_or_else(|e| e.to_compile_error().into())
parse_knobs(input, args.into()).unwrap_or_else(|e| e.to_compile_error().into())
}
fn parse_knobs(
mut input: syn::ItemFn,
args: syn::AttributeArgs,
args: proc_macro2::TokenStream,
) -> Result<TokenStream, syn::Error> {
let sig = &mut input.sig;
let body = &input.block;
@@ -62,7 +57,7 @@ fn parse_knobs(
let header = {
quote! {
#[#crate_name::tokio::test(#(#args)*)]
#[#crate_name::tokio::test( #args )]
}
};
@@ -76,25 +71,15 @@ fn parse_knobs(
#crate_name::tokio::spawn(fut).map(drop)
})
.into();
let timeout_task = #crate_name::tokio::time::delay_for(
if #crate_name::tokio::time::timeout(
std::time::Duration::from_secs(
std::env::var("SUBSTRATE_TEST_TIMEOUT")
.ok()
.and_then(|x| x.parse().ok())
.unwrap_or(600))
).fuse();
let actual_test_task = async move {
#body
}
.fuse();
#crate_name::futures::pin_mut!(timeout_task, actual_test_task);
#crate_name::futures::select! {
_ = timeout_task => {
panic!("The test took too long!");
},
_ = actual_test_task => {},
.unwrap_or(600)),
async move { #body },
).await.is_err() {
panic!("The test took too long!");
}
}
};
+1 -1
View File
@@ -12,6 +12,6 @@ publish = false
targets = ["x86_64-unknown-linux-gnu"]
[dev-dependencies]
tokio = { version = "0.2.13", features = ["macros"] }
tokio = { version = "1.10", features = ["macros"] }
test-utils = { version = "4.0.0-dev", path = "..", package = "substrate-test-utils" }
sc-service = { version = "0.10.0-dev", path = "../../client/service" }
+1 -1
View File
@@ -48,7 +48,7 @@ frame-system = { path = "../../frame/system" }
log = "0.4.8"
futures = "0.3.16"
tokio = { version = "0.2", features = ["signal"] }
tokio = { version = "1.10", features = ["signal"] }
# Calling RPC
jsonrpc-core = "18.0"
num-traits = "0.2.14"
+4 -4
View File
@@ -29,7 +29,7 @@ async fn panicking_test(_: TaskExecutor) {
panic!("boo!");
}
#[substrate_test_utils::test(max_threads = 2)]
#[substrate_test_utils::test(flavor = "multi_thread", worker_threads = 1)]
async fn basic_test_with_args(_: TaskExecutor) {
assert!(true);
}
@@ -41,14 +41,14 @@ async fn rename_argument(ex: TaskExecutor) {
assert!(true);
}
#[substrate_test_utils::test]
#[should_panic(expected = "test took too long")]
// NOTE: enable this test only after setting SUBSTRATE_TEST_TIMEOUT to a smaller value
//
// SUBSTRATE_TEST_TIMEOUT=1 cargo test -- --ignored timeout
#[substrate_test_utils::test]
#[should_panic(expected = "test took too long")]
#[ignore]
async fn timeout(_: TaskExecutor) {
tokio::time::delay_for(std::time::Duration::from_secs(
tokio::time::sleep(std::time::Duration::from_secs(
std::env::var("SUBSTRATE_TEST_TIMEOUT")
.expect("env var SUBSTRATE_TEST_TIMEOUT has been provided by the user")
.parse::<u64>()