mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-25 21:07:56 +00:00
Fix flaky test (#6131)
* Split test + decrease test timeout * fmt * spellcheck
This commit is contained in:
@@ -30,6 +30,7 @@ use sp_core::testing::TaskExecutor;
|
||||
|
||||
use std::{
|
||||
convert::Infallible,
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
task::{Context, Poll, Waker},
|
||||
@@ -391,6 +392,34 @@ macro_rules! arbitrary_order {
|
||||
};
|
||||
}
|
||||
|
||||
/// Future that yields the execution once and resolves
|
||||
/// immediately after.
|
||||
///
|
||||
/// Useful when one wants to poll the background task to completion
|
||||
/// before sending messages to it in order to avoid races.
|
||||
pub struct Yield(bool);
|
||||
|
||||
impl Yield {
|
||||
/// Returns new `Yield` future.
|
||||
pub fn new() -> Self {
|
||||
Self(false)
|
||||
}
|
||||
}
|
||||
|
||||
impl Future for Yield {
|
||||
type Output = ();
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
if !self.0 {
|
||||
self.0 = true;
|
||||
cx.waker().wake_by_ref();
|
||||
Poll::Pending
|
||||
} else {
|
||||
Poll::Ready(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user