Skip to content

Commit 8adec6d

Browse files
authored
Merge pull request #5050 from stacks-network/ci/fix-empty-sortitions
CI: fix the empty_sortitions signers test in CI
2 parents 468b1e4 + d165ed3 commit 8adec6d

File tree

1 file changed

+24
-21
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+24
-21
lines changed

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,35 +2054,38 @@ fn empty_sortition() {
20542054
.collect();
20552055
assert_eq!(signer_slot_ids.len(), num_signers);
20562056

2057-
// The miner's proposed block should get rejected by the signers
2058-
let start_polling = Instant::now();
2059-
let mut found_rejection = false;
2060-
while !found_rejection {
2061-
std::thread::sleep(Duration::from_secs(1));
2062-
let messages: Vec<SignerMessage> = StackerDB::get_messages(
2063-
stackerdb
2064-
.get_session_mut(&MessageSlotID::BlockResponse)
2065-
.expect("Failed to get BlockResponse stackerdb session"),
2066-
&signer_slot_ids,
2067-
)
2068-
.expect("Failed to get message from stackerdb");
2069-
for message in messages {
2057+
// The miner's proposed block should get rejected by all the signers
2058+
let mut found_rejections = Vec::new();
2059+
wait_for(short_timeout.as_secs(), || {
2060+
for slot_id in signer_slot_ids.iter() {
2061+
if found_rejections.contains(slot_id) {
2062+
continue;
2063+
}
2064+
let mut latest_msgs = StackerDB::get_messages(
2065+
stackerdb
2066+
.get_session_mut(&MessageSlotID::BlockResponse)
2067+
.expect("Failed to get BlockResponse stackerdb session"),
2068+
&[*slot_id]
2069+
).expect("Failed to get message from stackerdb");
2070+
assert!(latest_msgs.len() <= 1);
2071+
let Some(latest_msg) = latest_msgs.pop() else {
2072+
info!("No message yet from slot #{slot_id}, will wait to try again");
2073+
continue;
2074+
};
20702075
if let SignerMessage::BlockResponse(BlockResponse::Rejected(BlockRejection {
20712076
reason_code,
20722077
..
2073-
})) = message
2078+
})) = latest_msg
20742079
{
20752080
assert!(matches!(reason_code, RejectCode::SortitionViewMismatch));
2076-
found_rejection = true;
2081+
found_rejections.push(*slot_id);
20772082
} else {
2078-
panic!("Unexpected message type");
2083+
info!("Latest message from slot #{slot_id} isn't a block rejection, will wait to see if the signer updates to a rejection");
20792084
}
20802085
}
2081-
assert!(
2082-
start_polling.elapsed() <= short_timeout,
2083-
"Timed out after waiting for response from signer"
2084-
);
2085-
}
2086+
// wait until we've found rejections for all the signers
2087+
Ok(found_rejections.len() == signer_slot_ids.len())
2088+
}).unwrap();
20862089
signer_test.shutdown();
20872090
}
20882091

0 commit comments

Comments
 (0)