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