Fix flaky test (#6131)

* Split test + decrease test timeout

* fmt

* spellcheck
This commit is contained in:
Chris Sosnin
2022-10-10 10:06:44 +04:00
committed by GitHub
parent f614752c22
commit e4361b6d80
3 changed files with 63 additions and 20 deletions
@@ -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::*;