Avoid hangs in tests (#9949)

* Avoid hangs in tests

* set timeout for 10 mins.
This commit is contained in:
Squirrel
2021-10-07 10:08:57 +01:00
committed by GitHub
parent f4bffe6d0b
commit 9f1c3acb7d
+8 -3
View File
@@ -28,8 +28,10 @@ use std::{
pin::Pin, pin::Pin,
sync::Arc, sync::Arc,
task::{Context as FutureContext, Poll}, task::{Context as FutureContext, Poll},
time::Duration,
}; };
use async_std::future::timeout;
use futures::{future::BoxFuture, prelude::*}; use futures::{future::BoxFuture, prelude::*};
use libp2p::{build_multiaddr, PeerId}; use libp2p::{build_multiaddr, PeerId};
use log::trace; use log::trace;
@@ -1017,10 +1019,13 @@ where
/// Blocks the current thread until we are sync'ed. /// Blocks the current thread until we are sync'ed.
/// ///
/// Calls `poll_until_sync` repeatedly. /// Calls `poll_until_sync` repeatedly.
/// (If we've not synced within 10 mins then panic rather than hang.)
fn block_until_sync(&mut self) { fn block_until_sync(&mut self) {
futures::executor::block_on(futures::future::poll_fn::<(), _>(|cx| { futures::executor::block_on(timeout(
self.poll_until_sync(cx) Duration::from_secs(10 * 60),
})); futures::future::poll_fn::<(), _>(|cx| self.poll_until_sync(cx)),
))
.expect("sync didn't happen within 10 mins");
} }
/// Blocks the current thread until there are no pending packets. /// Blocks the current thread until there are no pending packets.