Skip to content

Commit

Permalink
fix(client): allow to request QueryBox
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <[email protected]>
  • Loading branch information
Erigara committed Jun 6, 2024
1 parent 7c7edf6 commit bf692a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
21 changes: 20 additions & 1 deletion client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl From<ResponseReport> for eyre::Report {
/// Output of a query
pub trait QueryOutput: Into<QueryOutputBox> + TryFrom<QueryOutputBox> {
/// Type of the query output
type Target: Clone;
type Target;

/// Construct query output from query response
fn new(output: Self, query_request: QueryResponseHandler<Self>) -> Self::Target;
Expand Down Expand Up @@ -309,6 +309,25 @@ where
}
}

impl QueryOutput for QueryOutputBox {
type Target = QueryResult<Self>;

fn new(output: Self, query_handler: QueryResponseHandler<Self>) -> Self::Target {
match output {
Self::Vec(v) => {
let query_handler = QueryResponseHandler::new(query_handler.query_request);
let set = ResultSet {
query_handler,
iter: v,
client_cursor: 0,
};
set.collect::<QueryResult<Vec<_>>>().map(Self::Vec)
}
other => Ok(other),
}
}
}

macro_rules! impl_query_output {
( $($ident:ty),+ $(,)? ) => { $(
impl QueryOutput for $ident {
Expand Down
12 changes: 7 additions & 5 deletions core/test_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,15 +892,17 @@ impl TestClient for Client {
<R::Output as QueryOutput>::Target: core::fmt::Debug,
<R::Output as TryFrom<QueryOutputBox>>::Error: Into<eyre::Error>,
{
let mut query_result = None;
for _ in 0..max_attempts {
query_result = match self.request(request.clone()) {
Ok(result) if f(result.clone()) => return Ok(()),
result => Some(result),
if let Ok(result) = self.request(request.clone()) {
if f(result) {
return Ok(());
}
};
thread::sleep(period);
}
Err(eyre::eyre!("Failed to wait for query request completion that would satisfy specified closure. Got this query result instead: {:?}", &query_result))
Err(eyre::eyre!(
"Failed to wait for query request completion that would satisfy specified closure"
))
}

fn poll_request<R: Query + Debug + Clone>(
Expand Down

0 comments on commit bf692a1

Please sign in to comment.