-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathload_test.go
102 lines (81 loc) · 2.6 KB
/
load_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package load
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
ginkgo "github.com/onsi/ginkgo/v2"
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/log"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/subnet-evm/tests"
"github.com/ava-labs/subnet-evm/tests/utils"
)
const (
// The load test requires 5 nodes
nodeCount = 5
subnetAName = "load-subnet-a"
)
var (
flagVars *e2e.FlagVars
repoRootPath = tests.GetRepoRootPath("tests/load")
)
func init() {
// Configures flags used to configure tmpnet
flagVars = e2e.RegisterFlags()
}
func TestE2E(t *testing.T) {
ginkgo.RunSpecs(t, "subnet-evm small load simulator test suite")
}
var _ = ginkgo.Describe("[Load Simulator]", ginkgo.Ordered, func() {
require := require.New(ginkgo.GinkgoT())
var env *e2e.TestEnvironment
ginkgo.BeforeAll(func() {
tc := e2e.NewTestContext()
genesisPath := filepath.Join(repoRootPath, "tests/load/genesis/genesis.json")
nodes := utils.NewTmpnetNodes(nodeCount)
env = e2e.NewTestEnvironment(
tc,
flagVars,
utils.NewTmpnetNetwork(
"subnet-evm-small-load",
nodes,
tmpnet.FlagsMap{},
utils.NewTmpnetSubnet(subnetAName, genesisPath, utils.DefaultChainConfig, nodes...),
),
)
})
ginkgo.It("basic subnet load test", ginkgo.Label("load"), func() {
network := env.GetNetwork()
subnet := network.GetSubnet(subnetAName)
require.NotNil(subnet)
blockchainID := subnet.Chains[0].ChainID
nodeURIs := tmpnet.GetNodeURIs(network.Nodes)
validatorIDs := set.NewSet[ids.NodeID](len(subnet.ValidatorIDs))
validatorIDs.Add(subnet.ValidatorIDs...)
rpcEndpoints := make([]string, 0, len(nodeURIs))
for _, nodeURI := range nodeURIs {
if !validatorIDs.Contains(nodeURI.NodeID) {
continue
}
rpcEndpoints = append(rpcEndpoints, fmt.Sprintf("%s/ext/bc/%s/rpc", nodeURI.URI, blockchainID))
}
commaSeparatedRPCEndpoints := strings.Join(rpcEndpoints, ",")
err := os.Setenv("RPC_ENDPOINTS", commaSeparatedRPCEndpoints)
require.NoError(err)
log.Info("Running load simulator...", "rpcEndpoints", commaSeparatedRPCEndpoints)
cmd := exec.Command("./scripts/run_simulator.sh")
cmd.Dir = repoRootPath
log.Info("Running load simulator script", "cmd", cmd.String())
out, err := cmd.CombinedOutput()
fmt.Printf("\nCombined output:\n\n%s\n", string(out))
require.NoError(err)
})
})