mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
testing: Prepare light client testing with substrate binary and add subxt-test macro (#1507)
* testing: Add long running light client flag and cfg aliases
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Expose clients depending on feature flags
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* subxt: Use unstable backend for light client
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Disable flaky lightclient tests
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* ci: Add long runnnig step
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Revert "subxt: Use unstable backend for light client"
This reverts commit ea6f3cc58b.
* ci: Long running tests for 60 mins
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* ci: Use 16 cores for light-client testing
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* ci: Isolate light-client testing to save CI minutes
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Retry on Tx::Dropped for lightclinet only
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Wait for more blocks for the lightclient init
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* subxt: Use unstable backend for light client
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Disable legacy RPC tests
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Disable sudo and contracts tests
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Retry constructing lightclient on read-proof errors
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Disable tx dynamic test
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* proc-macro: Timeout for tests
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Add timeout 800 seconds
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* proc-macro/tests: Adjust subxt-test proc-macro
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* proc-macro: Rename crate to subxt-test-proc-macro
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Use default subxt-proc-macro timeout
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* light-client: Remove println
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* subxt: Remove tokio as dependency, use it only for testing
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Chagne default timeout to 6 seconds
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* proc-macro: Add env timeout variable
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* ci: Add subxt env var for controling test timeouts
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* tests/tx-retries: Retry on `Non node available` error
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Use unstable backend for testing lightclient
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Remove old lightclient object
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* testing: Adjust for the new interface
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* backend/rpc: Allow older version of the initialized event
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* rpc/tests: Check initialized decodes correctly
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* ci: Reset workflow
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Apply cargo fmt
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Remove unused dep
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Remove gitmerge old file
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Remove unused dep
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* rename proc-macro to subxt-test-macro
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* tests: Remove txretries for lightclient
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* tests: Wait for 5 blocks for the lightclient full testing suite
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* tests: Group imports
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* macro: Rename const value
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
---------
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
|
||||
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||
// see LICENSE for license details.
|
||||
|
||||
extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
use quote::{format_ident, quote};
|
||||
use syn::{
|
||||
parse::{Parse, ParseStream},
|
||||
Error,
|
||||
};
|
||||
|
||||
/// Environment variable for setting the timeout for the test.
|
||||
const SUBXT_TEST_TIMEOUT: &str = "SUBXT_TEST_TIMEOUT";
|
||||
|
||||
/// Default timeout for the test.
|
||||
const DEFAULT_TIMEOUT_SECS: u64 = 60 * 6;
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn subxt_test(attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let subxt_attr = match syn::parse::<SubxtTestAttr>(attr) {
|
||||
Ok(subxt_attr) => subxt_attr,
|
||||
Err(err) => return err.into_compile_error().into(),
|
||||
};
|
||||
|
||||
// Timeout is determined by:
|
||||
// - The timeout attribute if it is set.
|
||||
// - The SUBXT_TEST_TIMEOUT environment variable if it is set.
|
||||
// - A default of 6 minutes.
|
||||
let timeout_duration = subxt_attr.timeout.unwrap_or_else(|| {
|
||||
std::env::var(SUBXT_TEST_TIMEOUT)
|
||||
.map(|str| str.parse().unwrap_or(DEFAULT_TIMEOUT_SECS))
|
||||
.unwrap_or(DEFAULT_TIMEOUT_SECS)
|
||||
});
|
||||
|
||||
let func: syn::ItemFn = match syn::parse(item) {
|
||||
Ok(func) => func,
|
||||
Err(err) => return err.into_compile_error().into(),
|
||||
};
|
||||
|
||||
let func_attrs = &func.attrs;
|
||||
let func_vis = &func.vis;
|
||||
let func_sig = &func.sig;
|
||||
let func_block = &func.block;
|
||||
|
||||
let mut inner_func_sig = func.sig.clone();
|
||||
inner_func_sig.ident = format_ident!("{}_inner", inner_func_sig.ident);
|
||||
let inner_func_name = &inner_func_sig.ident;
|
||||
|
||||
let result = quote! {
|
||||
#[tokio::test]
|
||||
#( #func_attrs )*
|
||||
#func_vis #func_sig {
|
||||
#func_vis #inner_func_sig
|
||||
#func_block
|
||||
|
||||
tokio::time::timeout(std::time::Duration::from_secs(#timeout_duration), #inner_func_name())
|
||||
.await
|
||||
.expect("Test timedout")
|
||||
}
|
||||
};
|
||||
result.into()
|
||||
}
|
||||
|
||||
mod keywords {
|
||||
syn::custom_keyword!(timeout);
|
||||
}
|
||||
|
||||
struct SubxtTestAttr {
|
||||
timeout: Option<u64>,
|
||||
}
|
||||
|
||||
impl Parse for SubxtTestAttr {
|
||||
fn parse(input: ParseStream) -> Result<Self, Error> {
|
||||
if input.is_empty() {
|
||||
return Ok(Self { timeout: None });
|
||||
}
|
||||
|
||||
let _keyword = input.parse::<keywords::timeout>()?;
|
||||
input.parse::<syn::token::Eq>()?;
|
||||
let timeout = input.parse::<syn::LitInt>()?.base10_parse::<u64>()?;
|
||||
|
||||
if !input.is_empty() {
|
||||
return Err(Error::new(
|
||||
input.span(),
|
||||
"Expected tokens: `timeout = value`",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
timeout: Some(timeout),
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user