Skip to content

Commit d99a308

Browse files
authored
execution/eth1: fix flake in TestValidateChainWithLastTxNumOfBlockAtStepBoundary (#18879)
fixes a flaky test I introduced in #18858 CI run: https://github.com/erigontech/erigon/actions/runs/21483225590/job/61885074571 ``` --- FAIL: TestValidateChainWithLastTxNumOfBlockAtStepBoundary (0.04s) ethereum_execution_test.go:57: Error Trace: /Users/runner/work/erigon/erigon/execution/eth1/ethereum_execution_test.go:57 Error: Not equal: expected: 0 actual : 5 Test: TestValidateChainWithLastTxNumOfBlockAtStepBoundary ```
1 parent 572e586 commit d99a308

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

execution/eth1/ethereum_execution_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
package eth1_test
22

33
import (
4+
"context"
45
"encoding/binary"
6+
"errors"
57
"math/big"
68
"testing"
9+
"time"
710

11+
"github.com/cenkalti/backoff/v4"
812
"github.com/holiman/uint256"
913
"github.com/stretchr/testify/require"
1014

1115
"github.com/erigontech/erigon/common"
1216
"github.com/erigontech/erigon/common/crypto"
17+
"github.com/erigontech/erigon/common/generics"
1318
"github.com/erigontech/erigon/common/u256"
1419
"github.com/erigontech/erigon/db/kv"
1520
"github.com/erigontech/erigon/execution/chain"
@@ -50,8 +55,14 @@ func TestValidateChainWithLastTxNumOfBlockAtStepBoundary(t *testing.T) {
5055
require.Len(t, chainPack.Blocks, 1)
5156
newBlock := eth1utils.ConvertBlockToRPC(chainPack.Blocks[0])
5257
exec := m.Eth1ExecutionService
53-
insertRes, err := exec.InsertBlocks(ctx, &executionproto.InsertBlocksRequest{
54-
Blocks: []*executionproto.Block{newBlock},
58+
insertRes, err := retryBusy(ctx, func() (*executionproto.InsertionResult, executionproto.ExecutionStatus, error) {
59+
r, err := exec.InsertBlocks(ctx, &executionproto.InsertBlocksRequest{
60+
Blocks: []*executionproto.Block{newBlock},
61+
})
62+
if err != nil {
63+
return nil, 0, err
64+
}
65+
return r, r.Result, nil
5566
})
5667
require.NoError(t, err)
5768
require.Equal(t, executionproto.ExecutionStatus_Success, insertRes.Result)
@@ -82,3 +93,24 @@ func TestValidateChainWithLastTxNumOfBlockAtStepBoundary(t *testing.T) {
8293
require.NoError(t, err)
8394
require.Equal(t, chainPack.Headers[0].Root, common.BytesToHash(root))
8495
}
96+
97+
func retryBusy[T any](ctx context.Context, f func() (T, executionproto.ExecutionStatus, error)) (T, error) {
98+
ctx, cancel := context.WithTimeout(ctx, time.Minute)
99+
defer cancel()
100+
var b backoff.BackOff
101+
b = backoff.NewConstantBackOff(time.Millisecond)
102+
b = backoff.WithContext(b, ctx)
103+
return backoff.RetryWithData(
104+
func() (T, error) {
105+
r, s, err := f()
106+
if err != nil {
107+
return generics.Zero[T](), backoff.Permanent(err) // no retries
108+
}
109+
if s == executionproto.ExecutionStatus_Busy {
110+
return generics.Zero[T](), errors.New("retrying busy")
111+
}
112+
return r, nil
113+
},
114+
b,
115+
)
116+
}

0 commit comments

Comments
 (0)