github.com/MetalBlockchain/subnet-evm@v0.4.9/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 "context" 8 "fmt" 9 "os" 10 "os/exec" 11 "strings" 12 "testing" 13 "time" 14 15 "github.com/MetalBlockchain/metalgo/api/health" 16 "github.com/MetalBlockchain/subnet-evm/tests/utils" 17 "github.com/ethereum/go-ethereum/log" 18 "github.com/go-cmd/cmd" 19 ginkgo "github.com/onsi/ginkgo/v2" 20 "github.com/onsi/gomega" 21 ) 22 23 var startCmd *cmd.Cmd 24 25 func TestE2E(t *testing.T) { 26 gomega.RegisterFailHandler(ginkgo.Fail) 27 ginkgo.RunSpecs(t, "subnet-evm small load simulator test suite") 28 } 29 30 // BeforeSuite starts an MetalGo process to use for the e2e tests 31 var _ = ginkgo.BeforeSuite(func() { 32 ctx, cancel := context.WithTimeout(context.Background(), time.Minute) 33 defer cancel() 34 35 wd, err := os.Getwd() 36 gomega.Expect(err).Should(gomega.BeNil()) 37 log.Info("Starting MetalGo node", "wd", wd) 38 startCmd, err = utils.RunCommand("./scripts/run.sh") 39 gomega.Expect(err).Should(gomega.BeNil()) 40 41 // Assumes that startCmd will launch a node with HTTP Port at [utils.DefaultLocalNodeURI] 42 healthClient := health.NewClient(utils.DefaultLocalNodeURI) 43 healthy, err := health.AwaitReady(ctx, healthClient, 5*time.Second) 44 gomega.Expect(err).Should(gomega.BeNil()) 45 gomega.Expect(healthy).Should(gomega.BeTrue()) 46 log.Info("MetalGo node is healthy") 47 }) 48 49 var _ = ginkgo.Describe("[Load Simulator]", ginkgo.Ordered, func() { 50 ginkgo.It("basic subnet load test", ginkgo.Label("load"), func() { 51 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) 52 defer cancel() 53 54 blockchainID := utils.CreateNewSubnet(ctx, "./tests/load/genesis/genesis.json") 55 56 rpcEndpoints := make([]string, 0, len(utils.NodeURIs)) 57 for _, uri := range []string{utils.DefaultLocalNodeURI} { // TODO: use NodeURIs instead, hack until fixing multi node in a network behavior 58 rpcEndpoints = append(rpcEndpoints, fmt.Sprintf("%s/ext/bc/%s/rpc", uri, blockchainID)) 59 } 60 commaSeparatedRPCEndpoints := strings.Join(rpcEndpoints, ",") 61 err := os.Setenv("RPC_ENDPOINTS", commaSeparatedRPCEndpoints) 62 gomega.Expect(err).Should(gomega.BeNil()) 63 64 log.Info("Sleeping with network running", "rpcEndpoints", commaSeparatedRPCEndpoints) 65 cmd := exec.Command("./scripts/run_simulator.sh") 66 log.Info("Running load simulator script", "cmd", cmd.String()) 67 68 out, err := cmd.CombinedOutput() 69 fmt.Printf("\nCombined output:\n\n%s\n", string(out)) 70 gomega.Expect(err).Should(gomega.BeNil()) 71 }) 72 }) 73 74 var _ = ginkgo.AfterSuite(func() { 75 gomega.Expect(startCmd).ShouldNot(gomega.BeNil()) 76 gomega.Expect(startCmd.Stop()).Should(gomega.BeNil()) 77 // TODO add a new node to bootstrap off of the existing node and ensure it can bootstrap all subnets 78 // created during the test 79 })