From c9b2490ab9210c276bb02a4559448b2d1bb9566c Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sun, 27 Aug 2023 05:28:36 -0400 Subject: [PATCH] Tweak tributary_test to handle a one-block variance Prior to the previous commit, whatever async scheduling occurred caused them to all have the same tip. Now, some are one block ahead of others. This adds tolerance for that, as it's an acceptable variance, so long as it's solely one block. --- coordinator/src/tests/tributary/chain.rs | 34 +++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/coordinator/src/tests/tributary/chain.rs b/coordinator/src/tests/tributary/chain.rs index 0b27d02e..d70d3f9e 100644 --- a/coordinator/src/tests/tributary/chain.rs +++ b/coordinator/src/tests/tributary/chain.rs @@ -1,4 +1,7 @@ -use std::time::{Duration, SystemTime}; +use std::{ + time::{Duration, SystemTime}, + collections::HashSet, +}; use zeroize::Zeroizing; use rand_core::{RngCore, CryptoRng, OsRng}; @@ -209,14 +212,25 @@ async fn tributary_test() { // TODO: Is there a better way to handle this? sleep(Duration::from_secs(1)).await; - // All tributaries should agree on the tip - let mut final_block = None; - for (_, tributary) in tributaries { - if final_block.is_none() { - final_block = Some(tributary.tip().await); - } - if tributary.tip().await != final_block.unwrap() { - panic!("tributary had different tip"); - } + // All tributaries should agree on the tip, within a block + let mut tips = HashSet::new(); + for (_, tributary) in &tributaries { + tips.insert(tributary.tip().await); } + assert!(tips.len() <= 2); + if tips.len() == 2 { + for tip in tips.iter() { + // Find a Tributary where this isn't the tip + for (_, tributary) in &tributaries { + let Some(after) = tributary.reader().block_after(tip) else { continue }; + // Make sure the block after is the other tip + assert!(tips.contains(&after)); + return; + } + } + } else { + assert_eq!(tips.len(), 1); + return; + } + panic!("tributary had different tip with a variance exceeding one block"); }