From 9f1c3acb7dfecb20ce02f9d140e95ae3d5bdd2de Mon Sep 17 00:00:00 2001 From: Squirrel Date: Thu, 7 Oct 2021 10:08:57 +0100 Subject: [PATCH] Avoid hangs in tests (#9949) * Avoid hangs in tests * set timeout for 10 mins. --- substrate/client/network/test/src/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/substrate/client/network/test/src/lib.rs b/substrate/client/network/test/src/lib.rs index bb49cef8c6..e547fa376b 100644 --- a/substrate/client/network/test/src/lib.rs +++ b/substrate/client/network/test/src/lib.rs @@ -28,8 +28,10 @@ use std::{ pin::Pin, sync::Arc, task::{Context as FutureContext, Poll}, + time::Duration, }; +use async_std::future::timeout; use futures::{future::BoxFuture, prelude::*}; use libp2p::{build_multiaddr, PeerId}; use log::trace; @@ -1017,10 +1019,13 @@ where /// Blocks the current thread until we are sync'ed. /// /// Calls `poll_until_sync` repeatedly. + /// (If we've not synced within 10 mins then panic rather than hang.) fn block_until_sync(&mut self) { - futures::executor::block_on(futures::future::poll_fn::<(), _>(|cx| { - self.poll_until_sync(cx) - })); + futures::executor::block_on(timeout( + 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.