@@ -3,6 +3,7 @@ import { times } from '@aztec/foundation/collection';
33import { Secp256k1Signer } from '@aztec/foundation/crypto' ;
44import { Fr } from '@aztec/foundation/fields' ;
55import { type Logger , createLogger } from '@aztec/foundation/log' ;
6+ import { retryUntil } from '@aztec/foundation/retry' ;
67import { sleep } from '@aztec/foundation/sleep' ;
78import { emptyChainConfig } from '@aztec/stdlib/config' ;
89import type { WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server' ;
@@ -142,11 +143,17 @@ describe('p2p client integration batch txs', () => {
142143 logger,
143144 } )
144145 ) . map ( x => x . client ) ;
146+ } ;
145147
148+ async function makeSureClientsAreStarted ( ) {
146149 // Give the nodes time to discover each other
147150 await sleep ( 4000 ) ;
151+ for ( const c of clients ) {
152+ await retryUntil ( async ( ) => ( await c . getPeers ( ) ) . length == clients . length - 1 , 'peers discovered' , 12 , 0.5 ) ;
153+ }
154+
148155 logger . info ( 'Finished waiting for clients to connect' ) ;
149- } ;
156+ }
150157
151158 it . only ( 'batch requester fetches all missing txs from multiple peers' , async ( ) => {
152159 const NUMBER_OF_PEERS = 4 ;
@@ -188,6 +195,7 @@ describe('p2p client integration batch txs', () => {
188195 }
189196
190197 await setupClients ( NUMBER_OF_PEERS , txPoolMocks ) ;
198+ await makeSureClientsAreStarted ( ) ;
191199
192200 const peerIds = clients . map ( client => ( client as any ) . p2pService . node . peerId ) ;
193201 connectionSampler . getPeerListSortedByConnectionCountAsc . mockReturnValue ( peerIds ) ;
@@ -206,6 +214,7 @@ describe('p2p client integration batch txs', () => {
206214 5_000 ,
207215 ( client0 as any ) . p2pService . reqresp ,
208216 connectionSampler ,
217+ ( ) => Promise . resolve ( true ) ,
209218 logger ,
210219 ) ;
211220
0 commit comments