Skip to content

Commit 22024f7

Browse files
authored
test: Fix TestBatchQueueThrottlingWithDAFailure (#2663)
## Overview Fixes TestBatchQueueThrottlingWithDAFailure test Minor updates
1 parent 6aa5f34 commit 22024f7

4 files changed

Lines changed: 37 additions & 14 deletions

File tree

block/components.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ func NewAggregatorComponents(
238238
genesis,
239239
logger,
240240
executor,
241+
reaping.DefaultInterval,
241242
)
242243
if err != nil {
243244
return nil, fmt.Errorf("failed to create reaper: %w", err)

block/internal/reaping/reaper.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,20 @@ type Reaper struct {
4242
}
4343

4444
// NewReaper creates a new Reaper instance with persistent seenTx storage.
45-
func NewReaper(exec coreexecutor.Executor, sequencer coresequencer.Sequencer, genesis genesis.Genesis, logger zerolog.Logger, executor *executing.Executor) (*Reaper, error) {
45+
func NewReaper(
46+
exec coreexecutor.Executor,
47+
sequencer coresequencer.Sequencer,
48+
genesis genesis.Genesis,
49+
logger zerolog.Logger,
50+
executor *executing.Executor,
51+
scrapeInterval time.Duration,
52+
) (*Reaper, error) {
4653
if executor == nil {
4754
return nil, errors.New("executor cannot be nil")
4855
}
49-
56+
if scrapeInterval == 0 {
57+
return nil, errors.New("scrape interval cannot be empty")
58+
}
5059
store, err := store.NewDefaultInMemoryKVStore()
5160
if err != nil {
5261
return nil, fmt.Errorf("failed to create reaper store: %w", err)
@@ -56,7 +65,7 @@ func NewReaper(exec coreexecutor.Executor, sequencer coresequencer.Sequencer, ge
5665
exec: exec,
5766
sequencer: sequencer,
5867
chainID: genesis.ChainID,
59-
interval: DefaultInterval, // eventually this can be made configurable via config.Node
68+
interval: scrapeInterval,
6069
logger: logger.With().Str("component", "reaper").Logger(),
6170
seenStore: store,
6271
executor: executor,
@@ -110,6 +119,10 @@ func (r *Reaper) SubmitTxs() {
110119
r.logger.Error().Err(err).Msg("failed to get txs from executor")
111120
return
112121
}
122+
if len(txs) == 0 {
123+
r.logger.Debug().Msg("no new txs")
124+
return
125+
}
113126

114127
var newTxs [][]byte
115128
for _, tx := range txs {

block/internal/reaping/reaper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func newTestExecutor(t *testing.T) *executing.Executor {
6161
func newTestReaper(t *testing.T, chainID string, execMock *testmocks.MockExecutor, seqMock *testmocks.MockSequencer, e *executing.Executor) *Reaper {
6262
t.Helper()
6363

64-
r, err := NewReaper(execMock, seqMock, genesis.Genesis{ChainID: chainID}, zerolog.Nop(), e)
64+
r, err := NewReaper(execMock, seqMock, genesis.Genesis{ChainID: chainID}, zerolog.Nop(), e, 100*time.Millisecond)
6565
require.NoError(t, err)
6666

6767
return r

node/single_sequencer_integration_test.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)