Skip to content

Commit 537aa52

Browse files
committed
try static ports in CI
1 parent 8d93549 commit 537aa52

File tree

6 files changed

+82
-96
lines changed

6 files changed

+82
-96
lines changed

book/src/SUMMARY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
- [Chainlink]()
3737
- [RPC]()
3838
- [Loki]()
39+
- [Testing](testing.md)
40+
- [Smoke](testing/smoke.md)
41+
- [Performance](testing/performance.md)
42+
- [Chaos](testing/chaos.md)
3943
- [Interactive](framework/interactive.md)
4044
- [Continuous Integration](ci/ci.md)
4145
- [Libraries](./libraries.md)

framework/chaos/chaos.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func ExecPumba(command string) (func(), error) {
1717
pumbaReq := testcontainers.ContainerRequest{
1818
Name: fmt.Sprintf("chaos-%s", uuid.NewString()[0:5]),
1919
Image: "gaiaadm/pumba",
20+
Labels: framework.DefaultTCLabels(),
2021
Privileged: true,
2122
Cmd: cmd,
2223
HostConfigModifier: func(h *container.HostConfig) {

framework/components/clnode/clnode.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"errors"
77
"fmt"
8+
"github.com/docker/docker/api/types/container"
89
"github.com/docker/go-connections/nat"
910
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1011
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/postgres"
@@ -48,6 +49,8 @@ type NodeInput struct {
4849
UserConfigOverrides string `toml:"user_config_overrides"`
4950
TestSecretsOverrides string `toml:"test_secrets_overrides"`
5051
UserSecretsOverrides string `toml:"user_secrets_overrides"`
52+
HTTPPort int `toml:"port"`
53+
P2PPort int `toml:"p2p_port"`
5154
}
5255

5356
// Output represents Chainlink node output, nodes and databases connection URLs
@@ -166,6 +169,24 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
166169
},
167170
WaitingFor: wait.ForLog("Listening and serving HTTP").WithStartupTimeout(2 * time.Minute),
168171
}
172+
if in.Node.HTTPPort != 0 && in.Node.P2PPort != 0 {
173+
req.HostConfigModifier = func(h *container.HostConfig) {
174+
h.PortBindings = nat.PortMap{
175+
"6688/tcp": []nat.PortBinding{
176+
{
177+
HostIP: "0.0.0.0",
178+
HostPort: fmt.Sprintf("%d/tcp", in.Node.HTTPPort),
179+
},
180+
},
181+
"6690/udp": []nat.PortBinding{
182+
{
183+
HostIP: "0.0.0.0",
184+
HostPort: fmt.Sprintf("%d/udp", in.Node.P2PPort),
185+
},
186+
},
187+
}
188+
}
189+
}
169190
files := []tc.ContainerFile{
170191
{
171192
HostFilePath: cfgPath.Name(),
@@ -242,13 +263,22 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
242263
if err != nil {
243264
return nil, err
244265
}
245-
mp, err := c.MappedPort(ctx, nat.Port(httpPort))
246-
if err != nil {
247-
return nil, err
248-
}
249-
mpP2P, err := c.MappedPort(ctx, nat.Port(p2pPort))
250-
if err != nil {
251-
return nil, err
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+
}
252282
}
253283

254284
return &NodeOut{

framework/components/simple_node_set/node_set.go

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ func NewSharedDBNodeSet(in *Input, bcOut *blockchain.Output, fakeUrl string) (*O
3939
}
4040
switch in.OverrideMode {
4141
case "all":
42-
out, err = oneNodeSharedDBConfiguration(in, bcOut, fakeUrl, false)
42+
out, err = sharedDBSetup(in, bcOut, fakeUrl, false)
4343
if err != nil {
4444
return nil, err
4545
}
4646
case "each":
47-
out, err = oneNodeSharedDBConfiguration(in, bcOut, fakeUrl, true)
47+
out, err = sharedDBSetup(in, bcOut, fakeUrl, true)
4848
if err != nil {
4949
return nil, err
5050
}
@@ -59,65 +59,7 @@ func printOut(out *Output) {
5959
}
6060
}
6161

62-
// TODO: it seems we can use one DB for now
63-
// TODO: remove
64-
func NewNodeSet(in *Input, bcOut *blockchain.Output, fakeUrl string) (*Output, error) {
65-
if in.Out != nil && in.Out.UseCache {
66-
return in.Out, nil
67-
}
68-
nodeOuts := make([]*clnode.Output, 0)
69-
eg := &errgroup.Group{}
70-
mu := &sync.Mutex{}
71-
for i := 0; i < in.Nodes; i++ {
72-
i := i
73-
eg.Go(func() error {
74-
net, err := clnode.NewNetworkCfgOneNetworkAllNodes(bcOut)
75-
if err != nil {
76-
return err
77-
}
78-
79-
nodeSpec := &clnode.Input{
80-
DataProviderURL: fakeUrl,
81-
DbInput: in.NodeSpecs[i].DbInput,
82-
Node: &clnode.NodeInput{
83-
Image: in.NodeSpecs[i].Node.Image,
84-
Name: fmt.Sprintf("node%d", i),
85-
PullImage: in.NodeSpecs[i].Node.PullImage,
86-
CapabilitiesBinaryPaths: in.NodeSpecs[i].Node.CapabilitiesBinaryPaths,
87-
CapabilityContainerDir: in.NodeSpecs[i].Node.CapabilityContainerDir,
88-
TestConfigOverrides: net,
89-
UserConfigOverrides: in.NodeSpecs[i].Node.UserConfigOverrides,
90-
TestSecretsOverrides: in.NodeSpecs[i].Node.TestSecretsOverrides,
91-
UserSecretsOverrides: in.NodeSpecs[i].Node.UserSecretsOverrides,
92-
},
93-
}
94-
95-
dbOut, err := postgres.NewPostgreSQL(in.NodeSpecs[i].DbInput)
96-
if err != nil {
97-
return err
98-
}
99-
o, err := clnode.NewNode(nodeSpec, dbOut)
100-
if err != nil {
101-
return err
102-
}
103-
mu.Lock()
104-
nodeOuts = append(nodeOuts, o)
105-
mu.Unlock()
106-
return nil
107-
})
108-
}
109-
if err := eg.Wait(); err != nil {
110-
return nil, err
111-
}
112-
out := &Output{
113-
UseCache: true,
114-
CLNodes: nodeOuts,
115-
}
116-
in.Out = out
117-
return out, nil
118-
}
119-
120-
func oneNodeSharedDBConfiguration(in *Input, bcOut *blockchain.Output, fakeUrl string, overrideEach bool) (*Output, error) {
62+
func sharedDBSetup(in *Input, bcOut *blockchain.Output, fakeUrl string, overrideEach bool) (*Output, error) {
12163
dbOut, err := postgres.NewPostgreSQL(in.NodeSpecs[0].DbInput)
12264
if err != nil {
12365
return nil, err
@@ -147,6 +89,8 @@ func oneNodeSharedDBConfiguration(in *Input, bcOut *blockchain.Output, fakeUrl s
14789
DataProviderURL: fakeUrl,
14890
DbInput: in.NodeSpecs[overrideIdx].DbInput,
14991
Node: &clnode.NodeInput{
92+
HTTPPort: in.NodeSpecs[overrideIdx].Node.HTTPPort + i,
93+
P2PPort: in.NodeSpecs[overrideIdx].Node.P2PPort + i,
15094
Image: in.NodeSpecs[overrideIdx].Node.Image,
15195
Name: nodeName,
15296
PullImage: in.NodeSpecs[overrideIdx].Node.PullImage,

framework/examples/myproject/load.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
[nodeset.node_specs.node]
2222
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
2323
pull_image = false
24+
port = 5000
25+
p2p_port = 5100

framework/examples/myproject/load_test.go

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import (
77
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
88
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake"
99
ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set"
10-
"github.com/smartcontractkit/chainlink-testing-framework/wasp"
1110
"github.com/stretchr/testify/require"
12-
"os"
1311
"testing"
1412
"time"
1513
)
@@ -31,37 +29,44 @@ func TestLoad(t *testing.T) {
3129
out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker)
3230
require.NoError(t, err)
3331

34-
var lokiCfg *wasp.LokiConfig
35-
// temp fix, we can't reach shared Loki instance in CI
36-
if os.Getenv("CI") != "true" {
37-
lokiCfg = wasp.NewEnvLokiConfig()
38-
}
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+
//}
3937

40-
c, err := clclient.NewCLDefaultClients(out.CLNodes, framework.L)
38+
_, err = clclient.NewCLDefaultClients(out.CLNodes, framework.L)
4139
require.NoError(t, err)
4240

4341
t.Run("run the cluster and simulate slow network", func(t *testing.T) {
44-
p, err := wasp.NewProfile().
45-
Add(wasp.NewGenerator(&wasp.Config{
46-
T: t,
47-
LoadType: wasp.RPS,
48-
Schedule: wasp.Combine(
49-
wasp.Steps(1, 1, 9, 30*time.Second),
50-
wasp.Plain(10, 30*time.Second),
51-
wasp.Steps(10, -1, 10, 30*time.Second),
52-
),
53-
Gun: NewCLNodeGun(c[0], "bridges"),
54-
Labels: map[string]string{
55-
"gen_name": "cl_node_api_call",
56-
"branch": "example",
57-
"commit": "example",
58-
},
59-
LokiConfig: lokiCfg,
60-
})).
61-
Run(false)
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")
6265
require.NoError(t, err)
63-
_, err = chaos.ExecPumba("netem --tc-image=gaiadocker/iproute2 --duration=1m delay --time=300 re2:node.*")
66+
time.Sleep(5 * time.Second)
67+
_, err = clclient.NewCLDefaultClients(out.CLNodes, framework.L)
6468
require.NoError(t, err)
65-
p.Wait()
69+
70+
//p.Wait()
6671
})
6772
}

0 commit comments

Comments
 (0)