From 0302701c98c7572e39ce345a76413dc6db65a30e Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Mon, 6 Mar 2023 09:47:52 +0000 Subject: [PATCH] node: limit number of loops in `routes_to` The `routes_to` function can loop infinitely during test. To prevent this from happening a number of tries variable is added. It checks that the number of tries does not exceed 30, which gives the function about 3 seconds to complete -- due to the call to `thread::sleep` using 100ms. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-node/src/test/environment.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/radicle-node/src/test/environment.rs b/radicle-node/src/test/environment.rs index 5b61e92e..35775e20 100644 --- a/radicle-node/src/test/environment.rs +++ b/radicle-node/src/test/environment.rs @@ -165,7 +165,13 @@ impl NodeHandle { /// Wait until this node's routing table contains the given routes. #[track_caller] pub fn routes_to(&self, routes: &[(Id, NodeId)]) { + let mut tries = 0; loop { + // ~3s to converge to the correct routes + if tries > 30 { + panic!("Node::routes_to: routing tables did not converge to include given routes") + } + let mut remaining: BTreeSet<_> = routes.iter().collect(); for (rid, nid) in self.handle.routing().unwrap() { @@ -179,6 +185,7 @@ impl NodeHandle { if remaining.is_empty() { break; } + tries += 1; thread::sleep(Duration::from_millis(100)); } log::debug!(target: "test", "Node {} routes to {:?}", self.id, routes);