Skip to content

Commit 4f1c7e1

Browse files
committed
try only static ports
1 parent 537aa52 commit 4f1c7e1

File tree

7 files changed

+152
-70
lines changed

7 files changed

+152
-70
lines changed

framework/components/clnode/clnode.go

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
)
2020

2121
const (
22-
Port = "6688"
23-
P2PPort = "6690"
22+
DefaultHTTPPort = "6688"
23+
DefaultP2PPort = "6690"
2424
)
2525

2626
var (
@@ -144,8 +144,8 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
144144
return nil, err
145145
}
146146

147-
httpPort := fmt.Sprintf("%s/tcp", Port)
148-
p2pPort := fmt.Sprintf("%s/udp", P2PPort)
147+
httpPort := fmt.Sprintf("%s/tcp", DefaultHTTPPort)
148+
p2pPort := fmt.Sprintf("%s/udp", DefaultP2PPort)
149149
var containerName string
150150
if in.Node.Name != "" {
151151
containerName = in.Node.Name
@@ -263,29 +263,33 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
263263
if err != nil {
264264
return nil, err
265265
}
266-
var (
267-
mp nat.Port
268-
mpP2P nat.Port
269-
)
270-
if in.Node.HTTPPort != 0 && in.Node.P2PPort != 0 {
271-
mp = nat.Port(fmt.Sprintf("%d/tcp", in.Node.HTTPPort))
272-
mpP2P = nat.Port(fmt.Sprintf("%d/udp", in.Node.P2PPort))
273-
} else {
274-
mp, err = c.MappedPort(ctx, nat.Port(httpPort))
275-
if err != nil {
276-
return nil, err
277-
}
278-
mpP2P, err = c.MappedPort(ctx, nat.Port(p2pPort))
279-
if err != nil {
280-
return nil, err
281-
}
282-
}
266+
//var (
267+
// mp nat.Port
268+
// mpP2P nat.Port
269+
//)
270+
//if in.Node.HTTPPort != 0 && in.Node.P2PPort != 0 {
271+
// mp = nat.Port(fmt.Sprintf("%d/tcp", in.Node.HTTPPort))
272+
// mpP2P = nat.Port(fmt.Sprintf("%d/udp", in.Node.P2PPort))
273+
//}
274+
//else {
275+
// mp, err = c.MappedPort(ctx, nat.Port(httpPort))
276+
// if err != nil {
277+
// return nil, err
278+
// }
279+
// mpP2P, err = c.MappedPort(ctx, nat.Port(p2pPort))
280+
// if err != nil {
281+
// return nil, err
282+
// }
283+
//}
284+
285+
mp := nat.Port(fmt.Sprintf("%d/tcp", in.Node.HTTPPort))
286+
mpP2P := nat.Port(fmt.Sprintf("%d/udp", in.Node.P2PPort))
283287

284288
return &NodeOut{
285289
HostURL: fmt.Sprintf("http://%s:%s", host, mp.Port()),
286290
HostP2PURL: fmt.Sprintf("http://%s:%s", host, mpP2P.Port()),
287-
DockerURL: fmt.Sprintf("http://%s:%s", containerName, Port),
288-
DockerP2PUrl: fmt.Sprintf("http://%s:%s", containerName, P2PPort),
291+
DockerURL: fmt.Sprintf("http://%s:%s", containerName, DefaultHTTPPort),
292+
DockerP2PUrl: fmt.Sprintf("http://%s:%s", containerName, DefaultP2PPort),
289293
}, nil
290294
}
291295

@@ -296,7 +300,7 @@ type DefaultCLNodeConfig struct {
296300

297301
func generateDefaultConfig(in *Input) (string, error) {
298302
config := DefaultCLNodeConfig{
299-
HTTPPort: Port,
303+
HTTPPort: DefaultHTTPPort,
300304
SecureCookies: false,
301305
}
302306
tmpl, err := template.New("toml").Parse(defaultConfigTmpl)

framework/components/simple_node_set/node_set.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ import (
1111
"sync"
1212
)
1313

14+
const (
15+
DefaultHTTPPortStaticRangeStart = 10000
16+
DefaultP2PStaticRangeStart = 12000
17+
)
18+
1419
type Input struct {
15-
Nodes int `toml:"nodes" validate:"required"`
16-
OverrideMode string `toml:"override_mode" validate:"required,oneof=all each"`
17-
NodeSpecs []*clnode.Input `toml:"node_specs"`
18-
Out *Output `toml:"out"`
20+
Nodes int `toml:"nodes" validate:"required"`
21+
HTTPPortRangeStart int `toml:"http_port_range_start"`
22+
P2PPortRangeStart int `toml:"p2p_port_range_start"`
23+
OverrideMode string `toml:"override_mode" validate:"required,oneof=all each"`
24+
NodeSpecs []*clnode.Input `toml:"node_specs"`
25+
Out *Output `toml:"out"`
1926
}
2027

2128
type Output struct {
@@ -65,6 +72,18 @@ func sharedDBSetup(in *Input, bcOut *blockchain.Output, fakeUrl string, override
6572
return nil, err
6673
}
6774
nodeOuts := make([]*clnode.Output, 0)
75+
76+
var (
77+
httpPortRangeStart = DefaultHTTPPortStaticRangeStart
78+
p2pPortRangeStart = DefaultP2PStaticRangeStart
79+
)
80+
if in.HTTPPortRangeStart != 0 {
81+
httpPortRangeStart = in.HTTPPortRangeStart
82+
}
83+
if in.P2PPortRangeStart != 0 {
84+
p2pPortRangeStart = in.P2PPortRangeStart
85+
}
86+
6887
eg := &errgroup.Group{}
6988
mu := &sync.Mutex{}
7089
for i := 0; i < in.Nodes; i++ {
@@ -89,8 +108,8 @@ func sharedDBSetup(in *Input, bcOut *blockchain.Output, fakeUrl string, override
89108
DataProviderURL: fakeUrl,
90109
DbInput: in.NodeSpecs[overrideIdx].DbInput,
91110
Node: &clnode.NodeInput{
92-
HTTPPort: in.NodeSpecs[overrideIdx].Node.HTTPPort + i,
93-
P2PPort: in.NodeSpecs[overrideIdx].Node.P2PPort + i,
111+
HTTPPort: httpPortRangeStart + i,
112+
P2PPort: p2pPortRangeStart + i,
94113
Image: in.NodeSpecs[overrideIdx].Node.Image,
95114
Name: nodeName,
96115
PullImage: in.NodeSpecs[overrideIdx].Node.PullImage,

framework/examples/myproject/.envrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export TESTCONTAINERS_RYUK_DISABLED=true
22
export PRIVATE_KEY="..."
33
# load test
44
export LOKI_TENANT_ID=promtail
5-
export LOKI_URL=http://localhost:3030/loki/api/v1/push
5+
export LOKI_URL=http://localhost:3030/loki/api/v1/push
6+
export RESTY_DEBUG=true
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
[blockchain_a]
3+
chain_id = "31337"
4+
image = "f4hrenh9it/foundry:latest"
5+
port = "8545"
6+
type = "anvil"
7+
8+
[data_provider]
9+
port = 9111
10+
11+
[nodeset]
12+
nodes = 5
13+
override_mode = "all"
14+
15+
[[nodeset.node_specs]]
16+
17+
[nodeset.node_specs.db]
18+
image = "postgres:15.6"
19+
pull_image = true
20+
21+
[nodeset.node_specs.node]
22+
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
23+
pull_image = false
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package examples
2+
3+
import (
4+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
5+
"github.com/smartcontractkit/chainlink-testing-framework/framework/chaos"
6+
"github.com/smartcontractkit/chainlink-testing-framework/framework/clclient"
7+
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
8+
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake"
9+
ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set"
10+
"github.com/stretchr/testify/require"
11+
"testing"
12+
"time"
13+
)
14+
15+
type CfgChaos struct {
16+
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
17+
MockerDataProvider *fake.Input `toml:"data_provider" validate:"required"`
18+
NodeSet *ns.Input `toml:"nodeset" validate:"required"`
19+
}
20+
21+
func TestChaos(t *testing.T) {
22+
in, err := framework.Load[CfgChaos](t)
23+
require.NoError(t, err)
24+
25+
bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
26+
require.NoError(t, err)
27+
dp, err := fake.NewFakeDataProvider(in.MockerDataProvider)
28+
require.NoError(t, err)
29+
out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker)
30+
require.NoError(t, err)
31+
32+
c, err := clclient.NewCLDefaultClients(out.CLNodes, framework.L)
33+
require.NoError(t, err)
34+
35+
t.Run("run the cluster and simulate slow network", func(t *testing.T) {
36+
// example commands for Pumba:
37+
// stop --duration=1s --restart re2:node0 # stop one container for 1s and restart
38+
// "netem --tc-image=gaiadocker/iproute2 --duration=1m delay --time=300 re2:node.* # slow network
39+
_, err = chaos.ExecPumba("stop --duration=10s --restart re2:node0")
40+
require.NoError(t, err)
41+
time.Sleep(15 * time.Second)
42+
// we need to reconnect since we've rebooted some containers
43+
_, _, err = c[0].ReadBridges()
44+
require.NoError(t, err)
45+
})
46+
}

framework/examples/myproject/load.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,4 @@
2020

2121
[nodeset.node_specs.node]
2222
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
23-
pull_image = false
24-
port = 5000
25-
p2p_port = 5100
23+
pull_image = false

framework/examples/myproject/load_test.go

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package examples
22

33
import (
44
"github.com/smartcontractkit/chainlink-testing-framework/framework"
5-
"github.com/smartcontractkit/chainlink-testing-framework/framework/chaos"
65
"github.com/smartcontractkit/chainlink-testing-framework/framework/clclient"
76
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
87
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake"
98
ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set"
9+
"github.com/smartcontractkit/chainlink-testing-framework/wasp"
1010
"github.com/stretchr/testify/require"
11+
"os"
1112
"testing"
1213
"time"
1314
)
@@ -29,44 +30,34 @@ func TestLoad(t *testing.T) {
2930
out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker)
3031
require.NoError(t, err)
3132

32-
//var lokiCfg *wasp.LokiConfig
33-
//// temp fix, we can't reach shared Loki instance in CI
34-
//if os.Getenv("CI") != "true" {
35-
// lokiCfg = wasp.NewEnvLokiConfig()
36-
//}
33+
var lokiCfg *wasp.LokiConfig
34+
// temp fix, we can't reach shared Loki instance in CI
35+
if os.Getenv("CI") != "true" {
36+
lokiCfg = wasp.NewEnvLokiConfig()
37+
}
3738

38-
_, err = clclient.NewCLDefaultClients(out.CLNodes, framework.L)
39+
c, err := clclient.NewCLDefaultClients(out.CLNodes, framework.L)
3940
require.NoError(t, err)
4041

41-
t.Run("run the cluster and simulate slow network", func(t *testing.T) {
42-
//p, err := wasp.NewProfile().
43-
// Add(wasp.NewGenerator(&wasp.Config{
44-
// T: t,
45-
// LoadType: wasp.RPS,
46-
// Schedule: wasp.Combine(
47-
// wasp.Steps(1, 1, 9, 30*time.Second),
48-
// wasp.Plain(10, 30*time.Second),
49-
// wasp.Steps(10, -1, 10, 30*time.Second),
50-
// ),
51-
// Gun: NewCLNodeGun(c[0], "bridges"),
52-
// Labels: map[string]string{
53-
// "gen_name": "cl_node_api_call",
54-
// "branch": "example",
55-
// "commit": "example",
56-
// },
57-
// LokiConfig: lokiCfg,
58-
// })).
59-
// Run(false)
60-
//require.NoError(t, err)
61-
// example commands for Pumba:
62-
// stop --duration=1s --restart re2:node0 # stop one container for 1s and restart
63-
// "netem --tc-image=gaiadocker/iproute2 --duration=1m delay --time=300 re2:node.* # slow network
64-
_, err = chaos.ExecPumba("stop --duration=1s --restart re2:node0")
42+
t.Run("load test chainlink nodes", func(t *testing.T) {
43+
_, err := wasp.NewProfile().
44+
Add(wasp.NewGenerator(&wasp.Config{
45+
T: t,
46+
LoadType: wasp.RPS,
47+
Schedule: wasp.Combine(
48+
wasp.Steps(1, 1, 9, 30*time.Second),
49+
wasp.Plain(10, 30*time.Second),
50+
wasp.Steps(10, -1, 10, 30*time.Second),
51+
),
52+
Gun: NewCLNodeGun(c[0], "bridges"),
53+
Labels: map[string]string{
54+
"gen_name": "cl_node_api_call",
55+
"branch": "example",
56+
"commit": "example",
57+
},
58+
LokiConfig: lokiCfg,
59+
})).
60+
Run(true)
6561
require.NoError(t, err)
66-
time.Sleep(5 * time.Second)
67-
_, err = clclient.NewCLDefaultClients(out.CLNodes, framework.L)
68-
require.NoError(t, err)
69-
70-
//p.Wait()
7162
})
7263
}

0 commit comments

Comments
 (0)