fix tributary sync test

This commit is contained in:
akildemir 2023-06-28 20:02:57 +03:00 committed by Luke Parker
parent 8c020abb86
commit 790fe7ee23

View file

@ -35,10 +35,11 @@ async fn sync_test() {
// Have the rest form a P2P net
let mut tributary_arcs = vec![];
let mut p2p_threads = vec![];
for (i, (p2p, tributary)) in tributaries.drain(..).enumerate() {
let tributary = Arc::new(RwLock::new(tributary));
tributary_arcs.push(tributary.clone());
tokio::spawn(handle_p2p(
let thread = tokio::spawn(handle_p2p(
Ristretto::generator() * *keys[i],
p2p,
Arc::new(RwLock::new(HashMap::from([(
@ -46,6 +47,7 @@ async fn sync_test() {
ActiveTributary { spec: spec.clone(), tributary },
)]))),
));
p2p_threads.push(thread);
}
let tributaries = tributary_arcs;
@ -112,9 +114,17 @@ async fn sync_test() {
assert!(syncer_tributary.read().await.tip().await != syncer_tip);
// Verify it's now participating in consensus
// Because only `t` validators are used in a commit, check several commits
// This should be biased in favor of the syncer since we're using the syncer's view of the commit
for _ in 0 .. 10 {
// Because only `t` validators are used in a commit, take n - t nodes offline
// leaving only `t` nodes. Which should force it to participate in the consensus
// of next blocks.
let n = (spec.n() - spec.t()) as usize;
for t in p2p_threads.iter().take(n) {
t.abort();
}
// wait for a block
sleep(Duration::from_secs(block_time)).await;
let syncer_tributary = syncer_tributary.read().await;
if syncer_tributary
.reader()
@ -126,7 +136,6 @@ async fn sync_test() {
{
return;
}
sleep(Duration::from_secs(block_time)).await;
}
panic!("synced tributary didn't start participating in consensus");
}