@@ -308,8 +308,8 @@ func TestBatchQueueThrottlingWithDAFailure(t *testing.T) {
308308 // Set up configuration with low limits to trigger throttling quickly
309309 config := getTestConfig (t , 1 )
310310 config .Node .MaxPendingHeadersAndData = 3 // Low limit to quickly reach pending limit after DA failure
311- config .Node .BlockTime = evconfig.DurationWrapper {Duration : 100 * time .Millisecond }
312- config .DA .BlockTime = evconfig.DurationWrapper {Duration : 1 * time .Second } // Longer DA time to ensure blocks are produced first
311+ config .Node .BlockTime = evconfig.DurationWrapper {Duration : 25 * time .Millisecond }
312+ config .DA .BlockTime = evconfig.DurationWrapper {Duration : 100 * time .Millisecond } // Longer DA time to ensure blocks are produced first
313313
314314 // Create test components
315315 executor , sequencer , dummyDA , p2pClient , ds , _ , stopDAHeightTicker := createTestComponents (t , config )
@@ -327,23 +327,22 @@ func TestBatchQueueThrottlingWithDAFailure(t *testing.T) {
327327 node , cleanup := createNodeWithCustomComponents (t , config , executor , sequencer , dummyDAImpl , p2pClient , ds , func () {})
328328 defer cleanup ()
329329
330- ctx , cancel := context .WithCancel (context . Background ())
330+ ctx , cancel := context .WithCancel (t . Context ())
331331 defer cancel ()
332332
333333 var runningWg sync.WaitGroup
334334 startNodeInBackground (t , []* FullNode {node }, []context.Context {ctx }, & runningWg , 0 )
335335
336336 // Wait for the node to start producing blocks
337- require . NoError ( waitForFirstBlock ( node , Store ) )
337+ waitForBlockN ( t , 1 , node , config . Node . BlockTime . Duration )
338338
339339 // Inject some initial transactions to get the system working
340340 for i := 0 ; i < 5 ; i ++ {
341341 dummyExecutor .InjectTx ([]byte (fmt .Sprintf ("initial-tx-%d" , i )))
342342 }
343343
344- // Wait for at least 5 blocks to be produced before simulating DA failure
345- require .NoError (waitForAtLeastNBlocks (node , 5 , Store ))
346- t .Log ("Initial 5 blocks produced successfully" )
344+ waitForBlockN (t , 2 , node , config .Node .BlockTime .Duration )
345+ t .Log ("Initial blocks produced successfully" )
347346
348347 // Get the current height before DA failure
349348 initialHeight , err := getNodeHeight (node , Store )
@@ -366,7 +365,7 @@ func TestBatchQueueThrottlingWithDAFailure(t *testing.T) {
366365 return
367366 default :
368367 dummyExecutor .InjectTx ([]byte (fmt .Sprintf ("tx-after-da-failure-%d" , i )))
369- time .Sleep (10 * time . Millisecond ) // Inject faster than block time
368+ time .Sleep (config . Node . BlockTime . Duration / 2 ) // Inject faster than block time
370369 }
371370 }
372371 }()
@@ -405,7 +404,17 @@ func TestBatchQueueThrottlingWithDAFailure(t *testing.T) {
405404
406405 t .Log ("NOTE: This test uses DummySequencer. In a real deployment with SingleSequencer," )
407406 t .Log ("the batch queue would fill up and return ErrQueueFull, providing backpressure." )
407+ }
408408
409- // Shutdown
410- shutdownAndWait (t , []context.CancelFunc {cancel }, & runningWg , 10 * time .Second )
409+ // waitForBlockN waits for the node to produce a block with height >= n.
410+ func waitForBlockN (t * testing.T , n uint64 , node * FullNode , blockInterval time.Duration , timeout ... time.Duration ) {
411+ t .Helper ()
412+ if len (timeout ) == 0 {
413+ timeout = []time.Duration {time .Duration (n + 1 )* blockInterval + time .Second / 2 }
414+ }
415+ require .Eventually (t , func () bool {
416+ got , err := getNodeHeight (node , Store )
417+ require .NoError (t , err )
418+ return got >= n
419+ }, timeout [0 ], blockInterval / 2 )
411420}
0 commit comments