Skip to content

Commit

Permalink
feat: enables selection and execution of specific e2e benchmark tests (
Browse files Browse the repository at this point in the history
…#3595)

Closes #3588

Now, you can pass the test name as an arument:
```
 go run ./test/e2e/benchmark TwoNodeSimple  -v
```
And at the end you will see
```
test-e2e-benchmark2024/06/18 15:44:38 --- ✅ PASS: TwoNodeSimple 
```
  • Loading branch information
staheri14 authored Jun 20, 2024
1 parent af2a7e3 commit daaaf53
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
61 changes: 61 additions & 0 deletions test/e2e/benchmark/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"log"
"os"
"strings"
)

func main() {
logger := log.New(os.Stdout, "test-e2e-benchmark", log.LstdFlags)

tests := []Test{
{"TwoNodeSimple", TwoNodeSimple},
}

// check the test name passed as an argument and run it
specificTestFound := false
for _, arg := range os.Args[1:] {
for _, test := range tests {
if test.Name == arg {
runTest(logger, test)
specificTestFound = true
break
}
}
}

if !specificTestFound {
logger.Println("No particular test specified. Running all tests.")
logger.Println("go run ./test/e2e/benchmark <test_name> to run a specific test")
logger.Printf("Valid tests are: %s\n\n", getTestNames(tests))
// if no specific test is passed, run all tests
for _, test := range tests {
runTest(logger, test)
}
}
}

type TestFunc func(*log.Logger) error

type Test struct {
Name string
Func TestFunc
}

func runTest(logger *log.Logger, test Test) {
logger.Printf("=== RUN %s", test.Name)
err := test.Func(logger)
if err != nil {
logger.Fatalf("--- ERROR %s: %v", test.Name, err)
}
logger.Printf("--- ✅ PASS: %s \n\n", test.Name)
}

func getTestNames(tests []Test) string {
testNames := make([]string, 0, len(tests))
for _, test := range tests {
testNames = append(testNames, test.Name)
}
return strings.Join(testNames, ", ")
}
13 changes: 3 additions & 10 deletions test/e2e/benchmark/throughput.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@ const (
seed = 42
)

func main() {
if err := E2EThroughput(); err != nil {
log.Fatalf("--- ERROR Throughput test: %v", err.Error())
}
}

func E2EThroughput() error {
func TwoNodeSimple(logger *log.Logger) error {
latestVersion, err := testnet.GetLatestVersion()
testnet.NoError("failed to get latest version", err)

log.Println("=== RUN E2EThroughput", "version:", latestVersion)
logger.Println("=== RUN TwoNodeSimple", "version:", latestVersion)

manifest := Manifest{
ChainID: "test-e2e-throughput",
ChainID: "test-e2e-two-node-simple",
Validators: 2,
ValidatorResource: testnet.DefaultResources,
TxClientsResource: testnet.DefaultResources,
Expand Down Expand Up @@ -106,6 +100,5 @@ func E2EThroughput() error {
return fmt.Errorf("expected at least 10 transactions, got %d", totalTxs)
}

log.Println("--- PASS ✅: E2EThroughput")
return nil
}

0 comments on commit daaaf53

Please sign in to comment.