Skip to content

Commit

Permalink
limit automation load test deployment concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel committed Apr 29, 2024
1 parent d4cfdd6 commit 3baa7ad
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
16 changes: 14 additions & 2 deletions integration-tests/actions/automationv2/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,18 @@ func (r registrationResult) GetResult() common.Hash {
return r.txHash
}

func (a *AutomationTest) RegisterUpkeeps(upkeepConfigs []UpkeepConfig) ([]common.Hash, error) {
func (a *AutomationTest) RegisterUpkeeps(upkeepConfigs []UpkeepConfig, maxConcurrency int) ([]common.Hash, error) {
concurrency, err := actions_seth.GetAndAssertCorrectConcurrency(a.ChainClient, 1)
if err != nil {
return nil, err
}

if concurrency > maxConcurrency {
concurrency = maxConcurrency
a.Logger.Debug().
Msgf("Concurrency is higher than max concurrency, setting concurrency to %d", concurrency)
}

var registerUpkeep = func(resultCh chan registrationResult, errorCh chan error, executorNum int, upkeepConfig UpkeepConfig) {
keyNum := executorNum + 1 // key 0 is the root key
var registrationRequest []byte
Expand Down Expand Up @@ -684,12 +690,18 @@ func (c confirmationResult) GetResult() UpkeepId {
return c.upkeepID
}

func (a *AutomationTest) ConfirmUpkeepsRegistered(registrationTxHashes []common.Hash) ([]*big.Int, error) {
func (a *AutomationTest) ConfirmUpkeepsRegistered(registrationTxHashes []common.Hash, maxConcurrency int) ([]*big.Int, error) {
concurrency, err := actions_seth.GetAndAssertCorrectConcurrency(a.ChainClient, 1)
if err != nil {
return nil, err
}

if concurrency > maxConcurrency {
concurrency = maxConcurrency
a.Logger.Debug().
Msgf("Concurrency is higher than max concurrency, setting concurrency to %d", concurrency)
}

var confirmUpkeep = func(resultCh chan confirmationResult, errorCh chan error, _ int, txHash common.Hash) {
receipt, err := a.ChainClient.Client.TransactionReceipt(context.Background(), txHash)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions integration-tests/load/automationv2_1/automationv2_1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,10 @@ Load Config:
expectedTotalUpkeepCount += *u.NumberOfUpkeeps
}

maxDeploymentConcurrency := 100

for _, u := range loadedTestConfig.Automation.Load {
deploymentData, err := deployConsumerAndTriggerContracts(l, u, a.ChainClient, multicallAddress, automationDefaultLinkFunds, a.LinkToken)
deploymentData, err := deployConsumerAndTriggerContracts(l, u, a.ChainClient, multicallAddress, maxDeploymentConcurrency, automationDefaultLinkFunds, a.LinkToken)
require.NoError(t, err, "Error deploying consumer and trigger contracts")

consumerContracts = append(consumerContracts, deploymentData.ConsumerContracts...)
Expand Down Expand Up @@ -480,10 +482,10 @@ Load Config:
}

require.Equal(t, expectedTotalUpkeepCount, len(upkeepConfigs), "Incorrect number of upkeep configs created")
registrationTxHashes, err := a.RegisterUpkeeps(upkeepConfigs)
registrationTxHashes, err := a.RegisterUpkeeps(upkeepConfigs, maxDeploymentConcurrency)
require.NoError(t, err, "Error registering upkeeps")

upkeepIds, err := a.ConfirmUpkeepsRegistered(registrationTxHashes)
upkeepIds, err := a.ConfirmUpkeepsRegistered(registrationTxHashes, maxDeploymentConcurrency)
require.NoError(t, err, "Error confirming upkeeps registered")
require.Equal(t, expectedTotalUpkeepCount, len(upkeepIds), "Incorrect number of upkeeps registered")

Expand Down
24 changes: 20 additions & 4 deletions integration-tests/load/automationv2_1/gun.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,35 @@ func (m *LogTriggerGun) Call(_ *wasp.Generator) *wasp.Response {
dividedData = append(dividedData, d[i:end])
}

resultCh := make(chan *wasp.Response, len(dividedData))

for _, a := range dividedData {
wg.Add(1)
go func(a [][]byte, m *LogTriggerGun) *wasp.Response {
go func(a [][]byte, m *LogTriggerGun) {
defer wg.Done()

_, err := contracts.MultiCallLogTriggerLoadGen(m.client, m.multiCallAddress, m.addresses, a)
if err != nil {
m.logger.Error().Err(err).Msg("Error calling MultiCallLogTriggerLoadGen")
return &wasp.Response{Error: err.Error(), Failed: true}
resultCh <- &wasp.Response{Error: err.Error(), Failed: true}
return
}
return &wasp.Response{}
resultCh <- &wasp.Response{}
}(a, m)
}
wg.Wait()
return &wasp.Response{}

r := &wasp.Response{}
for result := range resultCh {
if result.Failed {
r.Failed = true
if r.Error != "" {
r.Error += "; " + result.Error
} else {
r.Error = result.Error
}
}
}

return r
}
8 changes: 7 additions & 1 deletion integration-tests/load/automationv2_1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,20 @@ type task struct {
deployTrigger bool
}

func deployConsumerAndTriggerContracts(l zerolog.Logger, loadConfig aconfig.Load, chainClient *seth.Client, multicallAddress common.Address, automationDefaultLinkFunds *big.Int, linkToken contracts.LinkToken) (DeploymentData, error) {
func deployConsumerAndTriggerContracts(l zerolog.Logger, loadConfig aconfig.Load, chainClient *seth.Client, multicallAddress common.Address, maxConcurrency int, automationDefaultLinkFunds *big.Int, linkToken contracts.LinkToken) (DeploymentData, error) {
data := DeploymentData{}

concurrency, err := actions_seth.GetAndAssertCorrectConcurrency(chainClient, 1)
if err != nil {
return DeploymentData{}, err
}

if concurrency > maxConcurrency {
concurrency = maxConcurrency
l.Debug().
Msgf("Concurrency is higher than max concurrency, setting concurrency to %d", concurrency)
}

l.Debug().
Int("Number of Upkeeps", *loadConfig.NumberOfUpkeeps).
Int("Concurrency", concurrency).
Expand Down

0 comments on commit 3baa7ad

Please sign in to comment.