mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-25 19:57:56 +00:00
substrate runner: increase line read + dump CLI output if parsing fails (#1781)
* substrate runner: dump CLI output parsing fails * cargo fmt * Update testing/substrate-runner/src/lib.rs * fix grumbles * disable flaky test * ignore reconn test too * ignore more tests * fix tests * improve log parsing * Update testing/integration-tests/src/full_client/client/unstable_rpcs.rs * Update testing/integration-tests/src/full_client/client/unstable_rpcs.rs * fix nits * fix reconn test
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||
// see LICENSE for license details.
|
||||
|
||||
use crate::{subxt_test, test_context};
|
||||
use crate::{subxt_test, test_context, utils::consume_initial_blocks};
|
||||
use codec::{Compact, Encode};
|
||||
use futures::StreamExt;
|
||||
|
||||
@@ -94,6 +94,7 @@ async fn finalized_headers_subscription() -> Result<(), subxt::Error> {
|
||||
let api = ctx.client();
|
||||
|
||||
let mut sub = api.blocks().subscribe_finalized().await?;
|
||||
consume_initial_blocks(&mut sub).await;
|
||||
|
||||
// check that the finalized block reported lines up with the `latest_finalized_block_ref`.
|
||||
for _ in 0..2 {
|
||||
|
||||
@@ -420,29 +420,28 @@ async fn legacy_and_unstable_block_subscription_reconnect() {
|
||||
let api = api.clone();
|
||||
async move {
|
||||
let mut missed_blocks = false;
|
||||
(api.blocks()
|
||||
.subscribe_finalized()
|
||||
.await
|
||||
.unwrap()
|
||||
// Ignore `disconnected events`.
|
||||
// This will be emitted by the legacy backend for every reconnection.
|
||||
.filter(|item| {
|
||||
let disconnected = match item {
|
||||
Ok(_) => false,
|
||||
Err(e) => {
|
||||
if matches!(e, Error::Rpc(subxt::error::RpcError::DisconnectedWillReconnect(e)) if e.contains("Missed at least one block when the connection was lost")) {
|
||||
missed_blocks = true;
|
||||
}
|
||||
e.is_disconnected_will_reconnect()
|
||||
}
|
||||
};
|
||||
|
||||
futures::future::ready(!disconnected)
|
||||
})
|
||||
.take(num)
|
||||
.map(|x| x.unwrap().hash().to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.await, missed_blocks)
|
||||
let blocks =
|
||||
// Ignore `disconnected events`.
|
||||
// This will be emitted by the legacy backend for every reconnection.
|
||||
api.blocks().subscribe_finalized().await.unwrap().filter(|item| {
|
||||
let disconnected = match item {
|
||||
Ok(_) => false,
|
||||
Err(e) => {
|
||||
if matches!(e, Error::Rpc(subxt::error::RpcError::DisconnectedWillReconnect(e)) if e.contains("Missed at least one block when the connection was lost")) {
|
||||
missed_blocks = true;
|
||||
}
|
||||
e.is_disconnected_will_reconnect()
|
||||
}
|
||||
};
|
||||
|
||||
futures::future::ready(!disconnected)
|
||||
})
|
||||
.take(num)
|
||||
.map(|x| x.unwrap().hash().to_string())
|
||||
.collect::<Vec<String>>().await;
|
||||
|
||||
(blocks, missed_blocks)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
//! Just sanity checking some of the new RPC methods to try and
|
||||
//! catch differences as the implementations evolve.
|
||||
|
||||
use crate::{subxt_test, test_context, utils::node_runtime};
|
||||
use crate::{
|
||||
subxt_test, test_context,
|
||||
utils::{consume_initial_blocks, node_runtime},
|
||||
};
|
||||
use assert_matches::assert_matches;
|
||||
use codec::Encode;
|
||||
use futures::Stream;
|
||||
@@ -341,8 +344,11 @@ async fn transaction_v1_broadcast() {
|
||||
|
||||
// Subscribe to finalized blocks.
|
||||
let mut finalized_sub = api.blocks().subscribe_finalized().await.unwrap();
|
||||
|
||||
consume_initial_blocks(&mut finalized_sub).await;
|
||||
|
||||
// Expect the tx to be encountered in a maximum number of blocks.
|
||||
let mut num_blocks: usize = 10;
|
||||
let mut num_blocks: usize = 20;
|
||||
|
||||
// Submit the transaction.
|
||||
let _operation_id = rpc
|
||||
|
||||
@@ -8,9 +8,8 @@ mod wait_for_blocks;
|
||||
|
||||
pub use context::*;
|
||||
pub use node_proc::TestNodeProcess;
|
||||
pub use wait_for_blocks::*;
|
||||
|
||||
pub use subxt_test_macro::subxt_test;
|
||||
pub use wait_for_blocks::*;
|
||||
|
||||
/// The test timeout is set to 1 second.
|
||||
/// However, the test is sleeping for 5 seconds.
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
|
||||
// see LICENSE for license details.
|
||||
|
||||
use subxt::{client::OnlineClientT, Config};
|
||||
use subxt::{
|
||||
backend::StreamOf, blocks::Block, client::OnlineClientT, Config, Error, OnlineClient,
|
||||
SubstrateConfig,
|
||||
};
|
||||
|
||||
/// Wait for blocks to be produced before running tests. Specifically, we
|
||||
/// wait for one more finalized block to be produced, which is important because
|
||||
@@ -23,3 +26,25 @@ pub async fn wait_for_number_of_blocks<C: Config>(
|
||||
sub.next().await;
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumes the initial blocks from the stream of blocks to ensure that the stream is up-to-date.
|
||||
///
|
||||
/// This may be useful on the unstable backend when the initial blocks may be large
|
||||
/// and one relies on something to included in finalized block in ner future.
|
||||
pub async fn consume_initial_blocks(
|
||||
blocks: &mut StreamOf<Result<Block<SubstrateConfig, OnlineClient<SubstrateConfig>>, Error>>,
|
||||
) {
|
||||
use tokio::time::{interval_at, Duration, Instant};
|
||||
const MAX_DURATION: Duration = Duration::from_millis(200);
|
||||
|
||||
let mut now = interval_at(Instant::now() + MAX_DURATION, MAX_DURATION);
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = now.tick() => {
|
||||
break;
|
||||
}
|
||||
_ = blocks.next() => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user