Skip to content

Commit

Permalink
core/services/ocr2/plugins/ccip: fix racey TestIntegration_CCIP (#15572)
Browse files Browse the repository at this point in the history
Wrap simulated backend with an object that synchronizes Commit() calls
  • Loading branch information
makramkd authored Dec 9, 2024
1 parent 7b7815e commit a707433
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 2,787 deletions.
2 changes: 0 additions & 2 deletions core/services/ocr2/plugins/ccip/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
)

func TestIntegration_CCIP(t *testing.T) {
t.Skip("racey test, need to sync backend.Commit() calls")

// Run tke batches of tests for both pipeline and dynamic price getter setups.
// We will remove the pipeline batch once the feature is deleted from the code.
tests := []struct {
Expand Down
28 changes: 25 additions & 3 deletions core/services/ocr2/plugins/ccip/testhelpers/ccip_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"math/big"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -168,11 +169,32 @@ type MaybeRevertReceiver struct {
Strict bool
}

// Backend wraps a simulated backend with a mutex to make it safe for concurrent use
// Commit() in particular has caused races.
type Backend struct {
mu sync.Mutex
*simulated.Backend
}

func NewBackend(sim *simulated.Backend) *Backend {
return &Backend{
mu: sync.Mutex{},
Backend: sim,
}
}

func (b *Backend) Commit() common.Hash {
b.mu.Lock()
defer b.mu.Unlock()

return b.Backend.Commit()
}

type Common struct {
ChainID uint64
ChainSelector uint64
User *bind.TransactOpts
Chain *simulated.Backend
Chain *Backend
LinkToken *link_token_interface.LinkToken
LinkTokenPool *lock_release_token_pool.LockReleaseTokenPool
CustomToken *link_token_interface.LinkToken
Expand Down Expand Up @@ -1194,7 +1216,7 @@ func SetupCCIPContracts(t *testing.T, sourceChainID, sourceChainSelector, destCh
ChainID: sourceChainID,
ChainSelector: sourceChainSelector,
User: sourceUser,
Chain: sourceChain,
Chain: NewBackend(sourceChain),
LinkToken: sourceLinkToken,
LinkTokenPool: sourceLinkPool,
CustomToken: sourceCustomToken,
Expand All @@ -1214,7 +1236,7 @@ func SetupCCIPContracts(t *testing.T, sourceChainID, sourceChainSelector, destCh
ChainID: destChainID,
ChainSelector: destChainSelector,
User: destUser,
Chain: destChain,
Chain: NewBackend(destChain),
LinkToken: destLinkToken,
LinkTokenPool: destLinkPool,
CustomToken: destCustomToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
types3 "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/google/uuid"
"github.com/hashicorp/consul/sdk/freeport"
"github.com/jmoiron/sqlx"
Expand Down Expand Up @@ -369,7 +368,7 @@ func setupNodeCCIP(
owner *bind.TransactOpts,
port int64,
dbName string,
sourceChain *simulated.Backend, destChain *simulated.Backend,
sourceChain *testhelpers.Backend, destChain *testhelpers.Backend,
sourceChainID *big.Int, destChainID *big.Int,
bootstrapPeerID string,
bootstrapPort int64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (ks EthKeyStoreSim) Eth() keystore.Eth {

var _ keystore.Eth = EthKeyStoreSim{}.ETHKS

func ConfirmTxs(t *testing.T, txs []*ethtypes.Transaction, chain *simulated.Backend) {
func ConfirmTxs(t *testing.T, txs []*ethtypes.Transaction, chain *Backend) {
chain.Commit()
ctx := tests.Context(t)
for _, tx := range txs {
Expand Down
Loading

0 comments on commit a707433

Please sign in to comment.