Commit 4872837d authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-e2e: Retry the receipts fetcher test (#12794)

This is one of our flakiest tests since it's very dependent on the test runner's CPU usage.
parent 4c25686a
...@@ -9,6 +9,8 @@ import ( ...@@ -9,6 +9,8 @@ import (
"testing" "testing"
"time" "time"
"github.com/ethereum-optimism/optimism/op-service/retry"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
...@@ -104,32 +106,48 @@ func TestBasicRPCReceiptsFetcher_Concurrency(t *testing.T) { ...@@ -104,32 +106,48 @@ func TestBasicRPCReceiptsFetcher_Concurrency(t *testing.T) {
for _, rec := range receipts { for _, rec := range receipts {
recMap[rec.TxHash] = rec recMap[rec.TxHash] = rec
} }
mrpc := new(mockRPC)
rp := NewBasicRPCReceiptsFetcher(mrpc, batchSize)
// prepare mock boff := &retry.ExponentialStrategy{
var numCalls atomic.Int32 Min: 0,
mrpc.On("BatchCallContext", mock.Anything, mock.AnythingOfType("[]rpc.BatchElem")). Max: time.Second,
Run(func(args mock.Arguments) { MaxJitter: 100 * time.Millisecond,
numCalls.Add(1) }
els := args.Get(1).([]rpc.BatchElem) err := retry.Do0(context.Background(), 10, boff, func() error {
for _, el := range els { mrpc := new(mockRPC)
if el.Method == "eth_getTransactionReceipt" { rp := NewBasicRPCReceiptsFetcher(mrpc, batchSize)
txHash := el.Args[0].(common.Hash)
// The IterativeBatchCall expects that the values are written // prepare mock
// to the fields of the allocated *types.Receipt. var numCalls atomic.Int32
**(el.Result.(**types.Receipt)) = *recMap[txHash] mrpc.On("BatchCallContext", mock.Anything, mock.AnythingOfType("[]rpc.BatchElem")).
Run(func(args mock.Arguments) {
numCalls.Add(1)
els := args.Get(1).([]rpc.BatchElem)
for _, el := range els {
if el.Method == "eth_getTransactionReceipt" {
txHash := el.Args[0].(common.Hash)
// The IterativeBatchCall expects that the values are written
// to the fields of the allocated *types.Receipt.
**(el.Result.(**types.Receipt)) = *recMap[txHash]
}
} }
} }).
}). Return([]error{nil})
Return([]error{nil})
runConcurrentFetchingTest(t, rp, numFetchers, receipts, block) runConcurrentFetchingTest(t, rp, numFetchers, receipts, block)
mrpc.AssertExpectations(t) mrpc.AssertExpectations(t)
finalNumCalls := int(numCalls.Load()) finalNumCalls := int(numCalls.Load())
require.NotZero(finalNumCalls, "BatchCallContext should have been called.")
require.Less(finalNumCalls, numFetchers*numBatchCalls, "Some IterativeBatchCalls should have been shared.") if finalNumCalls == 0 {
return errors.New("batchCallContext should have been called")
}
if finalNumCalls >= numFetchers*numBatchCalls {
return errors.New("some IterativeBatchCalls should have been shared")
}
return nil
})
require.NoError(err)
} }
func runConcurrentFetchingTest(t *testing.T, rp ReceiptsProvider, numFetchers int, receipts types.Receipts, block *RPCBlock) { func runConcurrentFetchingTest(t *testing.T, rp ReceiptsProvider, numFetchers int, receipts types.Receipts, block *RPCBlock) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment