github.com/MetalBlockchain/subnet-evm@v0.6.3/tests/load/load_test.go (about) 1 // Copyright (C) 2023, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package load 5 6 import ( 7 "fmt" 8 "os" 9 "os/exec" 10 "path/filepath" 11 "strings" 12 "testing" 13 14 ginkgo "github.com/onsi/ginkgo/v2" 15 16 "github.com/onsi/gomega" 17 18 "github.com/stretchr/testify/require" 19 20 "github.com/ethereum/go-ethereum/log" 21 22 "github.com/MetalBlockchain/metalgo/config" 23 "github.com/MetalBlockchain/metalgo/ids" 24 "github.com/MetalBlockchain/metalgo/tests/fixture/e2e" 25 "github.com/MetalBlockchain/metalgo/tests/fixture/tmpnet" 26 "github.com/MetalBlockchain/metalgo/utils/set" 27 28 "github.com/MetalBlockchain/subnet-evm/tests" 29 "github.com/MetalBlockchain/subnet-evm/tests/utils" 30 ) 31 32 const ( 33 // The load test requires 5 nodes 34 nodeCount = 5 35 36 subnetAName = "load-subnet-a" 37 ) 38 39 var ( 40 flagVars *e2e.FlagVars 41 repoRootPath = tests.GetRepoRootPath("tests/load") 42 ) 43 44 func init() { 45 // Configures flags used to configure tmpnet 46 flagVars = e2e.RegisterFlags() 47 } 48 49 func TestE2E(t *testing.T) { 50 gomega.RegisterFailHandler(ginkgo.Fail) 51 ginkgo.RunSpecs(t, "subnet-evm small load simulator test suite") 52 } 53 54 var _ = ginkgo.Describe("[Load Simulator]", ginkgo.Ordered, func() { 55 require := require.New(ginkgo.GinkgoT()) 56 57 var env *e2e.TestEnvironment 58 59 ginkgo.BeforeAll(func() { 60 genesisPath := filepath.Join(repoRootPath, "tests/load/genesis/genesis.json") 61 62 // The load tests are flaky at high levels of evm logging, so leave it at 63 // the default level instead of raising it to debug (as the warp testing does). 64 chainConfig := tmpnet.FlagsMap{} 65 66 nodes := utils.NewTmpnetNodes(nodeCount) 67 68 env = e2e.NewTestEnvironment( 69 flagVars, 70 utils.NewTmpnetNetwork( 71 nodes, 72 tmpnet.FlagsMap{ 73 // The default tmpnet log level (debug) induces too much overhead for load testing. 74 config.LogLevelKey: "info", 75 }, 76 utils.NewTmpnetSubnet(subnetAName, genesisPath, chainConfig, nodes...), 77 ), 78 ) 79 }) 80 81 ginkgo.It("basic subnet load test", ginkgo.Label("load"), func() { 82 network := env.GetNetwork() 83 84 subnet := network.GetSubnet(subnetAName) 85 require.NotNil(subnet) 86 blockchainID := subnet.Chains[0].ChainID 87 88 nodeURIs := tmpnet.GetNodeURIs(network.Nodes) 89 validatorIDs := set.NewSet[ids.NodeID](len(subnet.ValidatorIDs)) 90 validatorIDs.Add(subnet.ValidatorIDs...) 91 rpcEndpoints := make([]string, 0, len(nodeURIs)) 92 for _, nodeURI := range nodeURIs { 93 if !validatorIDs.Contains(nodeURI.NodeID) { 94 continue 95 } 96 rpcEndpoints = append(rpcEndpoints, fmt.Sprintf("%s/ext/bc/%s/rpc", nodeURI.URI, blockchainID)) 97 } 98 commaSeparatedRPCEndpoints := strings.Join(rpcEndpoints, ",") 99 err := os.Setenv("RPC_ENDPOINTS", commaSeparatedRPCEndpoints) 100 require.NoError(err) 101 102 log.Info("Running load simulator...", "rpcEndpoints", commaSeparatedRPCEndpoints) 103 cmd := exec.Command("./scripts/run_simulator.sh") 104 cmd.Dir = repoRootPath 105 log.Info("Running load simulator script", "cmd", cmd.String()) 106 107 out, err := cmd.CombinedOutput() 108 fmt.Printf("\nCombined output:\n\n%s\n", string(out)) 109 require.NoError(err) 110 }) 111 })