-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add tests for unstable_backend #1765
base: master
Are you sure you want to change the base?
Conversation
} | ||
|
||
impl Data { | ||
async fn call_meth<'a>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async fn call_meth<'a>( | |
async fn call<'a>( |
(*method)(&mut self.data_table, &mut self.subscription_channel, params) | ||
} | ||
|
||
async fn call_subscription<'a>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async fn call_subscription<'a>( | |
async fn subscribe<'a>( |
|
||
type RpcResult<T> = Result<T, RpcError>; | ||
type Item = RpcResult<String>; | ||
pub type SubscriptionHandler = Box< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quite complicated type and a bit hard to read but I'm fine to remove the lifetimes and cloning the data for each call if it simplifies the code...
it just tests anyway
|
||
struct MockDataTable { | ||
items: HashMap<Vec<u8>, VecDeque<Item>>, | ||
pub enum Message<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dq: why is many Result<T, Error> and a single just T?
request: MockDataTable, | ||
subscription: Subscription, | ||
data_table: MockDataTable, | ||
subscription_channel: Option<Subscription>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move the subscription_channel to the subscription handler? or is this needed to keep the channel alive?
} | ||
Message::Single(item) => sender.send(item).await.unwrap(), | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
struct Data { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it a bit of strange call this type Data which has functionality to perform rpc calls and subscription + the mock data table.
I would rather remove this struct and move all this functionality to the MockedRpcClient or rename this to InnerMockedRpcClient
or something like that
Self { | ||
data: Data { | ||
data_table: MockDataTable::new(), | ||
subscription_channel: None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this always None
? can we remove it?
} | ||
} | ||
|
||
pub fn add_method(mut self, method_name: &str, meth: MethodHandler) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lots of meth ^^ :)
.add_mock_data_from_iter(response_data) | ||
.build(); | ||
|
||
let (backend, mut driver): (UnstableBackend<Conf>, _) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this unstable backend stuff to a helper function such as fn run_backend
? It's used for several tests
Ok(resp1 @ StorageResponse { .. }), | ||
Ok(resp2 @ StorageResponse { .. }), | ||
Err(Error::Other(s)) | ||
] if s == "errro" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo?
] if s == "errro" | |
] if s == "error" |
|
||
assert!(matches!( | ||
response, | ||
Err(Error::Other(reason)) if reason == "errro" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo?
Err(Error::Other(reason)) if reason == "errro" | |
Err(Error::Other(reason)) if reason == "error" |
self | ||
} | ||
|
||
pub fn add_mock_data_from_iter< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is the only way to add mock_data
, why not removing the from_iter
?
pub fn add_mock_data_from_iter< | |
pub fn add_mock_data< |
@@ -839,6 +874,22 @@ pub(crate) mod hashmap_as_tuple_list { | |||
deserializer.deserialize_any(HashMapVisitor(PhantomData)) | |||
} | |||
|
|||
/// Serialize a number as string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder rather move these helpers to the test module
@@ -778,6 +799,9 @@ pub(crate) mod unsigned_number_as_string { | |||
use serde::de::{Deserializer, Visitor}; | |||
use std::fmt; | |||
|
|||
#[cfg(test)] | |||
use serde::ser::Serializer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to test module?!
@@ -786,6 +810,14 @@ pub(crate) mod unsigned_number_as_string { | |||
deserializer.deserialize_any(NumberVisitor(std::marker::PhantomData)) | |||
} | |||
|
|||
/// Serialize a number as string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to test module?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work, I have mostly have comments to simplify the tests to make it a little easier to read.
I'll take a closer look at the test themselves in the next iteration
Description
As in the title. This PR adds tests for
UnstableBackend
implementation in subxt/backend.The tests are mostly about testing
StorageResponses
in different cases of reconnections.Pr uses a mocked
RpcClient
implementation for providing expected responses.Additional changes
MockRpcClient
to be usable across legacy backend and unstable_backend following suggestion from last PRPart of the work on #1677