Skip to content

Commit

Permalink
try only static ports
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov committed Nov 6, 2024
1 parent 537aa52 commit 4f1c7e1
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 70 deletions.
52 changes: 28 additions & 24 deletions framework/components/clnode/clnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
)

const (
Port = "6688"
P2PPort = "6690"
DefaultHTTPPort = "6688"
DefaultP2PPort = "6690"
)

var (
Expand Down Expand Up @@ -144,8 +144,8 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
return nil, err
}

httpPort := fmt.Sprintf("%s/tcp", Port)
p2pPort := fmt.Sprintf("%s/udp", P2PPort)
httpPort := fmt.Sprintf("%s/tcp", DefaultHTTPPort)
p2pPort := fmt.Sprintf("%s/udp", DefaultP2PPort)
var containerName string
if in.Node.Name != "" {
containerName = in.Node.Name
Expand Down Expand Up @@ -263,29 +263,33 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
if err != nil {
return nil, err
}
var (
mp nat.Port
mpP2P nat.Port
)
if in.Node.HTTPPort != 0 && in.Node.P2PPort != 0 {
mp = nat.Port(fmt.Sprintf("%d/tcp", in.Node.HTTPPort))
mpP2P = nat.Port(fmt.Sprintf("%d/udp", in.Node.P2PPort))
} else {
mp, err = c.MappedPort(ctx, nat.Port(httpPort))
if err != nil {
return nil, err
}
mpP2P, err = c.MappedPort(ctx, nat.Port(p2pPort))
if err != nil {
return nil, err
}
}
//var (
// mp nat.Port
// mpP2P nat.Port
//)
//if in.Node.HTTPPort != 0 && in.Node.P2PPort != 0 {
// mp = nat.Port(fmt.Sprintf("%d/tcp", in.Node.HTTPPort))
// mpP2P = nat.Port(fmt.Sprintf("%d/udp", in.Node.P2PPort))
//}
//else {
// mp, err = c.MappedPort(ctx, nat.Port(httpPort))
// if err != nil {
// return nil, err
// }
// mpP2P, err = c.MappedPort(ctx, nat.Port(p2pPort))
// if err != nil {
// return nil, err
// }
//}

mp := nat.Port(fmt.Sprintf("%d/tcp", in.Node.HTTPPort))
mpP2P := nat.Port(fmt.Sprintf("%d/udp", in.Node.P2PPort))

return &NodeOut{
HostURL: fmt.Sprintf("http://%s:%s", host, mp.Port()),
HostP2PURL: fmt.Sprintf("http://%s:%s", host, mpP2P.Port()),
DockerURL: fmt.Sprintf("http://%s:%s", containerName, Port),
DockerP2PUrl: fmt.Sprintf("http://%s:%s", containerName, P2PPort),
DockerURL: fmt.Sprintf("http://%s:%s", containerName, DefaultHTTPPort),
DockerP2PUrl: fmt.Sprintf("http://%s:%s", containerName, DefaultP2PPort),
}, nil
}

Expand All @@ -296,7 +300,7 @@ type DefaultCLNodeConfig struct {

func generateDefaultConfig(in *Input) (string, error) {
config := DefaultCLNodeConfig{
HTTPPort: Port,
HTTPPort: DefaultHTTPPort,
SecureCookies: false,
}
tmpl, err := template.New("toml").Parse(defaultConfigTmpl)
Expand Down
31 changes: 25 additions & 6 deletions framework/components/simple_node_set/node_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ import (
"sync"
)

const (
DefaultHTTPPortStaticRangeStart = 10000
DefaultP2PStaticRangeStart = 12000
)

type Input struct {
Nodes int `toml:"nodes" validate:"required"`
OverrideMode string `toml:"override_mode" validate:"required,oneof=all each"`
NodeSpecs []*clnode.Input `toml:"node_specs"`
Out *Output `toml:"out"`
Nodes int `toml:"nodes" validate:"required"`
HTTPPortRangeStart int `toml:"http_port_range_start"`
P2PPortRangeStart int `toml:"p2p_port_range_start"`
OverrideMode string `toml:"override_mode" validate:"required,oneof=all each"`
NodeSpecs []*clnode.Input `toml:"node_specs"`
Out *Output `toml:"out"`
}

type Output struct {
Expand Down Expand Up @@ -65,6 +72,18 @@ func sharedDBSetup(in *Input, bcOut *blockchain.Output, fakeUrl string, override
return nil, err
}
nodeOuts := make([]*clnode.Output, 0)

var (
httpPortRangeStart = DefaultHTTPPortStaticRangeStart
p2pPortRangeStart = DefaultP2PStaticRangeStart
)
if in.HTTPPortRangeStart != 0 {
httpPortRangeStart = in.HTTPPortRangeStart
}
if in.P2PPortRangeStart != 0 {
p2pPortRangeStart = in.P2PPortRangeStart
}

eg := &errgroup.Group{}
mu := &sync.Mutex{}
for i := 0; i < in.Nodes; i++ {
Expand All @@ -89,8 +108,8 @@ func sharedDBSetup(in *Input, bcOut *blockchain.Output, fakeUrl string, override
DataProviderURL: fakeUrl,
DbInput: in.NodeSpecs[overrideIdx].DbInput,
Node: &clnode.NodeInput{
HTTPPort: in.NodeSpecs[overrideIdx].Node.HTTPPort + i,
P2PPort: in.NodeSpecs[overrideIdx].Node.P2PPort + i,
HTTPPort: httpPortRangeStart + i,
P2PPort: p2pPortRangeStart + i,
Image: in.NodeSpecs[overrideIdx].Node.Image,
Name: nodeName,
PullImage: in.NodeSpecs[overrideIdx].Node.PullImage,
Expand Down
3 changes: 2 additions & 1 deletion framework/examples/myproject/.envrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export TESTCONTAINERS_RYUK_DISABLED=true
export PRIVATE_KEY="..."
# load test
export LOKI_TENANT_ID=promtail
export LOKI_URL=http://localhost:3030/loki/api/v1/push
export LOKI_URL=http://localhost:3030/loki/api/v1/push
export RESTY_DEBUG=true
23 changes: 23 additions & 0 deletions framework/examples/myproject/chaos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

[blockchain_a]
chain_id = "31337"
image = "f4hrenh9it/foundry:latest"
port = "8545"
type = "anvil"

[data_provider]
port = 9111

[nodeset]
nodes = 5
override_mode = "all"

[[nodeset.node_specs]]

[nodeset.node_specs.db]
image = "postgres:15.6"
pull_image = true

[nodeset.node_specs.node]
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
pull_image = false
46 changes: 46 additions & 0 deletions framework/examples/myproject/chaos_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package examples

import (
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/chaos"
"github.com/smartcontractkit/chainlink-testing-framework/framework/clclient"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake"
ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set"
"github.com/stretchr/testify/require"
"testing"
"time"
)

type CfgChaos struct {
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
MockerDataProvider *fake.Input `toml:"data_provider" validate:"required"`
NodeSet *ns.Input `toml:"nodeset" validate:"required"`
}

func TestChaos(t *testing.T) {
in, err := framework.Load[CfgChaos](t)
require.NoError(t, err)

bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
require.NoError(t, err)
dp, err := fake.NewFakeDataProvider(in.MockerDataProvider)
require.NoError(t, err)
out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker)
require.NoError(t, err)

c, err := clclient.NewCLDefaultClients(out.CLNodes, framework.L)
require.NoError(t, err)

t.Run("run the cluster and simulate slow network", func(t *testing.T) {
// example commands for Pumba:
// stop --duration=1s --restart re2:node0 # stop one container for 1s and restart
// "netem --tc-image=gaiadocker/iproute2 --duration=1m delay --time=300 re2:node.* # slow network
_, err = chaos.ExecPumba("stop --duration=10s --restart re2:node0")
require.NoError(t, err)
time.Sleep(15 * time.Second)
// we need to reconnect since we've rebooted some containers
_, _, err = c[0].ReadBridges()
require.NoError(t, err)
})
}
4 changes: 1 addition & 3 deletions framework/examples/myproject/load.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@

[nodeset.node_specs.node]
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
pull_image = false
port = 5000
p2p_port = 5100
pull_image = false
63 changes: 27 additions & 36 deletions framework/examples/myproject/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package examples

import (
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/chaos"
"github.com/smartcontractkit/chainlink-testing-framework/framework/clclient"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake"
ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set"
"github.com/smartcontractkit/chainlink-testing-framework/wasp"
"github.com/stretchr/testify/require"
"os"
"testing"
"time"
)
Expand All @@ -29,44 +30,34 @@ func TestLoad(t *testing.T) {
out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker)
require.NoError(t, err)

//var lokiCfg *wasp.LokiConfig
//// temp fix, we can't reach shared Loki instance in CI
//if os.Getenv("CI") != "true" {
// lokiCfg = wasp.NewEnvLokiConfig()
//}
var lokiCfg *wasp.LokiConfig
// temp fix, we can't reach shared Loki instance in CI
if os.Getenv("CI") != "true" {
lokiCfg = wasp.NewEnvLokiConfig()
}

_, err = clclient.NewCLDefaultClients(out.CLNodes, framework.L)
c, err := clclient.NewCLDefaultClients(out.CLNodes, framework.L)
require.NoError(t, err)

t.Run("run the cluster and simulate slow network", func(t *testing.T) {
//p, err := wasp.NewProfile().
// Add(wasp.NewGenerator(&wasp.Config{
// T: t,
// LoadType: wasp.RPS,
// Schedule: wasp.Combine(
// wasp.Steps(1, 1, 9, 30*time.Second),
// wasp.Plain(10, 30*time.Second),
// wasp.Steps(10, -1, 10, 30*time.Second),
// ),
// Gun: NewCLNodeGun(c[0], "bridges"),
// Labels: map[string]string{
// "gen_name": "cl_node_api_call",
// "branch": "example",
// "commit": "example",
// },
// LokiConfig: lokiCfg,
// })).
// Run(false)
//require.NoError(t, err)
// example commands for Pumba:
// stop --duration=1s --restart re2:node0 # stop one container for 1s and restart
// "netem --tc-image=gaiadocker/iproute2 --duration=1m delay --time=300 re2:node.* # slow network
_, err = chaos.ExecPumba("stop --duration=1s --restart re2:node0")
t.Run("load test chainlink nodes", func(t *testing.T) {
_, err := wasp.NewProfile().
Add(wasp.NewGenerator(&wasp.Config{
T: t,
LoadType: wasp.RPS,
Schedule: wasp.Combine(
wasp.Steps(1, 1, 9, 30*time.Second),
wasp.Plain(10, 30*time.Second),
wasp.Steps(10, -1, 10, 30*time.Second),
),
Gun: NewCLNodeGun(c[0], "bridges"),
Labels: map[string]string{
"gen_name": "cl_node_api_call",
"branch": "example",
"commit": "example",
},
LokiConfig: lokiCfg,
})).
Run(true)
require.NoError(t, err)
time.Sleep(5 * time.Second)
_, err = clclient.NewCLDefaultClients(out.CLNodes, framework.L)
require.NoError(t, err)

//p.Wait()
})
}

0 comments on commit 4f1c7e1

Please sign in to comment.