diff --git a/go.mod b/go.mod index 1a0656a2b5..c5e611da10 100644 --- a/go.mod +++ b/go.mod @@ -52,14 +52,7 @@ require ( gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce gopkg.in/yaml.v3 v3.0.1 pgregory.net/rapid v1.1.0 -) - -require ( - github.com/mattn/go-runewidth v0.0.15 // indirect - github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect - github.com/rivo/uniseg v0.4.7 // indirect - github.com/schollz/progressbar/v3 v3.14.2 // indirect - golang.org/x/term v0.19.0 // indirect + github.com/schollz/progressbar/v3 v3.14.2 ) require ( @@ -231,4 +224,8 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20240304161311-37d4d3c04a78 // indirect gotest.tools/v3 v3.0.2 // indirect lukechampine.com/blake3 v1.2.1 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect + github.com/rivo/uniseg v0.4.7 // indirect + golang.org/x/term v0.19.0 // indirect ) diff --git a/loadtest/runner/base_load_test_runner.go b/loadtest/runner/base_load_test_runner.go index a022189ee0..1c4668b6ea 100644 --- a/loadtest/runner/base_load_test_runner.go +++ b/loadtest/runner/base_load_test_runner.go @@ -20,8 +20,6 @@ import ( "golang.org/x/sync/errgroup" ) -const transactionRetryNum = 5 - type feeData struct { gasPrice *big.Int gasTipCap *big.Int @@ -85,7 +83,11 @@ func (r *BaseLoadTestRunner) createVUs() error { start := time.Now().UTC() bar := progressbar.Default(int64(r.cfg.VUs), "Creating virtual users") - defer bar.Close() + + defer func() { + _ = bar.Close() + fmt.Println("Creating virtual users took", time.Since(start)) + }() for i := 0; i < r.cfg.VUs; i++ { key, err := crypto.GenerateECDSAKey() @@ -94,11 +96,9 @@ func (r *BaseLoadTestRunner) createVUs() error { } r.vus = append(r.vus, &account{key: key}) - bar.Add(1) + _ = bar.Add(1) } - fmt.Println("Creating virtual users took", time.Since(start)) - return nil } @@ -112,7 +112,11 @@ func (r *BaseLoadTestRunner) fundVUs() error { start := time.Now().UTC() bar := progressbar.Default(int64(r.cfg.VUs), "Funding virtual users with native tokens") - defer bar.Close() + + defer func() { + _ = bar.Close() + fmt.Println("Funding took", time.Since(start)) + }() amountToFund := ethgo.Ether(1000) @@ -159,7 +163,7 @@ func (r *BaseLoadTestRunner) fundVUs() error { return fmt.Errorf("failed to mint ERC20 tokens to %s", vu.key.Address()) } - bar.Add(1) + _ = bar.Add(1) return nil } @@ -170,8 +174,6 @@ func (r *BaseLoadTestRunner) fundVUs() error { return err } - fmt.Println("Funding took", time.Since(start)) - return nil } @@ -214,21 +216,24 @@ func (r *BaseLoadTestRunner) waitForTxPoolToEmpty() error { // a map of block information, transaction statistics, and an error if any. func (r *BaseLoadTestRunner) waitForReceipts(txHashes []types.Hash) (map[uint64]blockInfo, []txStats) { fmt.Println("=============================================================") - start := time.Now().UTC() + start := time.Now().UTC() blockInfoMap := make(map[uint64]blockInfo) txToBlockMap := make(map[types.Hash]uint64) txnStats := make([]txStats, 0, len(txHashes)) - bar := progressbar.Default(int64(len(txHashes)), "Gathering receipts") - defer bar.Close() + + defer func() { + _ = bar.Close() + fmt.Println("Waiting for receipts took", time.Since(start)) + }() foundErrors := make([]error, 0) for _, txHash := range txHashes { if blockNum, exists := txToBlockMap[txHash]; exists { txnStats = append(txnStats, txStats{txHash, blockNum}) - bar.Add(1) + _ = bar.Add(1) continue } @@ -241,7 +246,7 @@ func (r *BaseLoadTestRunner) waitForReceipts(txHashes []types.Hash) (map[uint64] } txnStats = append(txnStats, txStats{txHash, receipt.BlockNumber}) - bar.Add(1) + _ = bar.Add(1) block, err := r.client.GetBlockByNumber(jsonrpc.BlockNumber(receipt.BlockNumber), true) if err != nil { @@ -271,10 +276,9 @@ func (r *BaseLoadTestRunner) waitForReceipts(txHashes []types.Hash) (map[uint64] } } - fmt.Println("Waiting for receipts took", time.Since(start)) - if len(foundErrors) > 0 { fmt.Println("Errors found while waiting for receipts:") + for _, err := range foundErrors { fmt.Println(err) } @@ -467,9 +471,12 @@ func (r *BaseLoadTestRunner) sendTransactions( start := time.Now().UTC() totalTxs := r.cfg.VUs * r.cfg.TxsPerUser foundErrs := make([]error, 0) - bar := progressbar.Default(int64(totalTxs), "Sending transactions") - defer bar.Close() + + defer func() { + _ = bar.Close() + fmt.Println("Sending transactions took", time.Since(start)) + }() allTxnHashes := make([]types.Hash, 0) @@ -501,10 +508,9 @@ func (r *BaseLoadTestRunner) sendTransactions( return nil, err } - fmt.Println("Sending transactions took", time.Since(start)) - if len(foundErrs) > 0 { fmt.Println("Errors found while sending transactions:") + for _, err := range foundErrs { fmt.Println(err) } diff --git a/loadtest/runner/eoa_runner.go b/loadtest/runner/eoa_runner.go index b162383fb2..e9b1e70486 100644 --- a/loadtest/runner/eoa_runner.go +++ b/loadtest/runner/eoa_runner.go @@ -121,7 +121,7 @@ func (e *EOARunner) sendTransactionsForUser(account *account, chainID *big.Int, } account.nonce++ - bar.Add(1) + _ = bar.Add(1) } return txRelayer.GetTxnHashes(), sendErrs, nil diff --git a/loadtest/runner/erc20_runner.go b/loadtest/runner/erc20_runner.go index b8a76332aa..8116096141 100644 --- a/loadtest/runner/erc20_runner.go +++ b/loadtest/runner/erc20_runner.go @@ -140,9 +140,12 @@ func (e *ERC20Runner) mintERC20TokenToVUs() error { fmt.Println("=============================================================") start := time.Now().UTC() - bar := progressbar.Default(int64(e.cfg.VUs), "Minting ERC20 tokens to VUs") - defer bar.Close() + + defer func() { + _ = bar.Close() + fmt.Printf("Minting ERC20 tokens took %s\n", time.Since(start)) + }() txRelayer, err := txrelayer.NewTxRelayer( txrelayer.WithClient(e.client), @@ -193,7 +196,7 @@ func (e *ERC20Runner) mintERC20TokenToVUs() error { return fmt.Errorf("failed to mint ERC20 tokens to %s", vu.key.Address()) } - bar.Add(1) + _ = bar.Add(1) return nil } @@ -204,8 +207,6 @@ func (e *ERC20Runner) mintERC20TokenToVUs() error { return err } - fmt.Printf("Minting ERC20 tokens took %s\n", time.Since(start)) - return nil } @@ -280,7 +281,7 @@ func (e *ERC20Runner) sendTransactionsForUser(account *account, chainID *big.Int } account.nonce++ - bar.Add(1) + _ = bar.Add(1) } return txRelayer.GetTxnHashes(), sendErrs, nil diff --git a/loadtest/runner/load_test_runner_test.go b/loadtest/runner/load_test_runner_test.go index 52c916869d..2295e10039 100644 --- a/loadtest/runner/load_test_runner_test.go +++ b/loadtest/runner/load_test_runner_test.go @@ -21,6 +21,8 @@ func TestMnemonic(t *testing.T) { } func TestLoadRunner(t *testing.T) { + t.Skip("this is only added for the sake of the example and running it in local") + cfg := LoadTestConfig{ Mnemonnic: "code code code code code code code code code code code quality", LoadTestType: "eoa",