mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 22:27:56 +00:00
don't use delays in tests (#5404)
This commit is contained in:
@@ -23,9 +23,8 @@ use sp_runtime::traits::{Zero, SaturatedConversion};
|
||||
use sp_runtime::generic::BlockId;
|
||||
use sp_runtime::transaction_validity::TransactionValidityError;
|
||||
|
||||
use futures::{prelude::*, channel::mpsc, stream::unfold};
|
||||
use futures::{prelude::*, channel::mpsc};
|
||||
use std::time::Duration;
|
||||
use futures_timer::Delay;
|
||||
|
||||
#[cfg(not(test))]
|
||||
const BACKGROUND_REVALIDATION_INTERVAL: Duration = Duration::from_millis(200);
|
||||
@@ -53,12 +52,6 @@ struct RevalidationWorker<Api: ChainApi> {
|
||||
|
||||
impl<Api: ChainApi> Unpin for RevalidationWorker<Api> {}
|
||||
|
||||
fn interval(duration: Duration) -> impl Stream<Item=()> + Unpin {
|
||||
unfold((), move |_| {
|
||||
Delay::new(duration).map(|_| Some(((), ())))
|
||||
}).map(drop)
|
||||
}
|
||||
|
||||
/// Revalidate batch of transaction.
|
||||
///
|
||||
/// Each transaction is validated against chain, and invalid are
|
||||
@@ -207,8 +200,13 @@ impl<Api: ChainApi> RevalidationWorker<Api> {
|
||||
/// It does two things: periodically tries to process some transactions
|
||||
/// from the queue and also accepts messages to enqueue some more
|
||||
/// transactions from the pool.
|
||||
pub async fn run(mut self, from_queue: mpsc::UnboundedReceiver<WorkerPayload<Api>>) {
|
||||
let interval = interval(BACKGROUND_REVALIDATION_INTERVAL).fuse();
|
||||
pub async fn run<R: intervalier::IntoStream>(
|
||||
mut self,
|
||||
from_queue: mpsc::UnboundedReceiver<WorkerPayload<Api>>,
|
||||
interval: R,
|
||||
) where R: Send, R::Guard: Send
|
||||
{
|
||||
let interval = interval.into_stream().fuse();
|
||||
let from_queue = from_queue.fuse();
|
||||
futures::pin_mut!(interval, from_queue);
|
||||
let this = &mut self;
|
||||
@@ -270,9 +268,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// New revalidation queue with background worker.
|
||||
pub fn new_background(api: Arc<Api>, pool: Arc<Pool<Api>>) ->
|
||||
(Self, Pin<Box<dyn Future<Output=()> + Send>>)
|
||||
pub fn new_with_interval<R: intervalier::IntoStream>(
|
||||
api: Arc<Api>,
|
||||
pool: Arc<Pool<Api>>,
|
||||
interval: R,
|
||||
) -> (Self, Pin<Box<dyn Future<Output=()> + Send>>)
|
||||
where R: Send + 'static, R::Guard: Send
|
||||
{
|
||||
let (to_worker, from_queue) = mpsc::unbounded();
|
||||
|
||||
@@ -285,7 +286,25 @@ where
|
||||
background: Some(to_worker),
|
||||
};
|
||||
|
||||
(queue, worker.run(from_queue).boxed())
|
||||
(queue, worker.run(from_queue, interval).boxed())
|
||||
}
|
||||
|
||||
/// New revalidation queue with background worker.
|
||||
pub fn new_background(api: Arc<Api>, pool: Arc<Pool<Api>>) ->
|
||||
(Self, Pin<Box<dyn Future<Output=()> + Send>>)
|
||||
{
|
||||
Self::new_with_interval(api, pool, intervalier::Interval::new(BACKGROUND_REVALIDATION_INTERVAL))
|
||||
}
|
||||
|
||||
/// New revalidation queue with background worker and test signal.
|
||||
#[cfg(test)]
|
||||
pub fn new_test(api: Arc<Api>, pool: Arc<Pool<Api>>) ->
|
||||
(Self, Pin<Box<dyn Future<Output=()> + Send>>, intervalier::BackSignalControl)
|
||||
{
|
||||
let (interval, notifier) = intervalier::BackSignalInterval::new(BACKGROUND_REVALIDATION_INTERVAL);
|
||||
let (queue, background) = Self::new_with_interval(api, pool, interval);
|
||||
|
||||
(queue, background, notifier)
|
||||
}
|
||||
|
||||
/// Queue some transaction for later revalidation.
|
||||
|
||||
Reference in New Issue
Block a user