@@ -2054,35 +2054,38 @@ fn empty_sortition() {
2054
2054
. collect ( ) ;
2055
2055
assert_eq ! ( signer_slot_ids. len( ) , num_signers) ;
2056
2056
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
+ } ;
2070
2075
if let SignerMessage :: BlockResponse ( BlockResponse :: Rejected ( BlockRejection {
2071
2076
reason_code,
2072
2077
..
2073
- } ) ) = message
2078
+ } ) ) = latest_msg
2074
2079
{
2075
2080
assert ! ( matches!( reason_code, RejectCode :: SortitionViewMismatch ) ) ;
2076
- found_rejection = true ;
2081
+ found_rejections . push ( * slot_id ) ;
2077
2082
} 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 " ) ;
2079
2084
}
2080
2085
}
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 ( ) ;
2086
2089
signer_test. shutdown ( ) ;
2087
2090
}
2088
2091
0 commit comments