forked from 0xPolygon/polygon-edge
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load test runner implementation (#194)
* Load test runner implementation * UTs build fix * Lint fix * load-test command * Better UX * add ZexCoin to test artifacts * add erc20 test name log * gas price increase * collect all errors for tx sending and just log them * stale sequence check (temp fix) * more gasPrice increase * gather receipt errors and print them * lint fix * feeData * Lint fix * fix * ERC721 support * results to json file * lint fix * remove comment * receipts gather in separate routines * remove receipts timeout from fund and deploy functions * ticker timeout and gasPrice increase * lock in gathering receipts * increase maxDemotionsNum * waitForTxPool flag, and gathering results in parallel * lint fix * fix ut * Go mod tidy * comments fix * lint fix * more statistics * small fix * small fix --------- Co-authored-by: Stefan Negovanović <stefan@ethernal.tech>
- Loading branch information
1 parent
5d6017f
commit 162382e
Showing
25 changed files
with
2,768 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package loadtest | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/0xPolygon/polygon-edge/command" | ||
"github.com/0xPolygon/polygon-edge/command/helper" | ||
"github.com/0xPolygon/polygon-edge/loadtest/runner" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
params loadTestParams | ||
) | ||
|
||
func GetCommand() *cobra.Command { | ||
loadTestCmd := &cobra.Command{ | ||
Use: "load-test", | ||
Short: "Runs a load test on a specified network", | ||
PreRunE: preRunCommand, | ||
Run: runCommand, | ||
} | ||
|
||
helper.RegisterJSONRPCFlag(loadTestCmd) | ||
|
||
setFlags(loadTestCmd) | ||
|
||
return loadTestCmd | ||
} | ||
|
||
func preRunCommand(cmd *cobra.Command, _ []string) error { | ||
params.jsonRPCAddress = helper.GetJSONRPCAddress(cmd) | ||
|
||
return params.validateFlags() | ||
} | ||
|
||
func setFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringVar( | ||
¶ms.mnemonic, | ||
mnemonicFlag, | ||
"", | ||
"the mnemonic used to generate and fund virtual users", | ||
) | ||
|
||
cmd.Flags().StringVar( | ||
¶ms.loadTestType, | ||
loadTestTypeFlag, | ||
"eoa", | ||
"the type of load test to run (supported types: eoa, erc20, erc721)", | ||
) | ||
|
||
cmd.Flags().StringVar( | ||
¶ms.loadTestName, | ||
loadTestNameFlag, | ||
"load test", | ||
"the name of the load test", | ||
) | ||
|
||
cmd.Flags().IntVar( | ||
¶ms.vus, | ||
vusFlag, | ||
1, | ||
"the number of virtual users", | ||
) | ||
|
||
cmd.Flags().IntVar( | ||
¶ms.txsPerUser, | ||
txsPerUserFlag, | ||
1, | ||
"the number of transactions per virtual user", | ||
) | ||
|
||
cmd.Flags().BoolVar( | ||
¶ms.dynamicTxs, | ||
dynamicTxsFlag, | ||
false, | ||
"indicates whether the load test should generate dynamic transactions", | ||
) | ||
|
||
cmd.Flags().DurationVar( | ||
¶ms.receiptsTimeout, | ||
receiptsTimeoutFlag, | ||
30*time.Second, | ||
"the timeout for waiting for transaction receipts", | ||
) | ||
|
||
cmd.Flags().DurationVar( | ||
¶ms.txPoolTimeout, | ||
txPoolTimeoutFlag, | ||
10*time.Minute, | ||
"the timeout for waiting for the transaction pool to empty", | ||
) | ||
|
||
cmd.Flags().BoolVar( | ||
¶ms.toJSON, | ||
saveToJSONFlag, | ||
false, | ||
"saves results to JSON file", | ||
) | ||
|
||
cmd.Flags().BoolVar( | ||
¶ms.waitForTxPoolToEmpty, | ||
waitForTxPoolToEmptyFlag, | ||
false, | ||
"waits for tx pool to empty before collecting results", | ||
) | ||
|
||
_ = cmd.MarkFlagRequired(mnemonicFlag) | ||
_ = cmd.MarkFlagRequired(loadTestTypeFlag) | ||
} | ||
|
||
func runCommand(cmd *cobra.Command, _ []string) { | ||
outputter := command.InitializeOutputter(cmd) | ||
defer outputter.WriteOutput() | ||
|
||
loadTestRunner := &runner.LoadTestRunner{} | ||
|
||
err := loadTestRunner.Run(runner.LoadTestConfig{ | ||
Mnemonnic: params.mnemonic, | ||
LoadTestType: params.loadTestType, | ||
LoadTestName: params.loadTestName, | ||
JSONRPCUrl: params.jsonRPCAddress, | ||
ReceiptsTimeout: params.receiptsTimeout, | ||
TxPoolTimeout: params.txPoolTimeout, | ||
VUs: params.vus, | ||
TxsPerUser: params.txsPerUser, | ||
DynamicTxs: params.dynamicTxs, | ||
ResultsToJSON: params.toJSON, | ||
WaitForTxPoolToEmpty: params.waitForTxPoolToEmpty, | ||
}) | ||
|
||
if err != nil { | ||
outputter.SetError(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package loadtest | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/0xPolygon/polygon-edge/loadtest/runner" | ||
) | ||
|
||
const ( | ||
mnemonicFlag = "mnemonic" | ||
loadTestTypeFlag = "type" | ||
loadTestNameFlag = "name" | ||
|
||
receiptsTimeoutFlag = "receipts-timeout" | ||
txPoolTimeoutFlag = "txpool-timeout" | ||
|
||
vusFlag = "vus" | ||
txsPerUserFlag = "txs-per-user" | ||
dynamicTxsFlag = "dynamic" | ||
|
||
saveToJSONFlag = "to-json" | ||
waitForTxPoolToEmptyFlag = "wait-txpool" | ||
) | ||
|
||
var ( | ||
errNoMnemonicProvided = errors.New("no mnemonic provided") | ||
errNoLoadTestTypeProvided = errors.New("no load test type provided") | ||
errUnsupportedLoadTestType = errors.New("unsupported load test type") | ||
errInvalidVUs = errors.New("vus must be greater than 0") | ||
errInvalidTxsPerUser = errors.New("txs-per-user must be greater than 0") | ||
) | ||
|
||
type loadTestParams struct { | ||
mnemonic string | ||
loadTestType string | ||
loadTestName string | ||
jsonRPCAddress string | ||
|
||
receiptsTimeout time.Duration | ||
txPoolTimeout time.Duration | ||
|
||
vus int | ||
txsPerUser int | ||
|
||
dynamicTxs bool | ||
toJSON bool | ||
waitForTxPoolToEmpty bool | ||
} | ||
|
||
func (ltp *loadTestParams) validateFlags() error { | ||
if ltp.mnemonic == "" { | ||
return errNoMnemonicProvided | ||
} | ||
|
||
if ltp.loadTestType == "" { | ||
return errNoLoadTestTypeProvided | ||
} | ||
|
||
if !runner.IsLoadTestSupported(ltp.loadTestType) { | ||
return errUnsupportedLoadTestType | ||
} | ||
|
||
if ltp.vus < 1 { | ||
return errInvalidVUs | ||
} | ||
|
||
if ltp.txsPerUser < 1 { | ||
return errInvalidTxsPerUser | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.