Skip to content

Commit

Permalink
try static ports in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov committed Nov 6, 2024
1 parent 8d93549 commit 537aa52
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 96 deletions.
4 changes: 4 additions & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
- [Chainlink]()
- [RPC]()
- [Loki]()
- [Testing](testing.md)
- [Smoke](testing/smoke.md)
- [Performance](testing/performance.md)
- [Chaos](testing/chaos.md)
- [Interactive](framework/interactive.md)
- [Continuous Integration](ci/ci.md)
- [Libraries](./libraries.md)
Expand Down
1 change: 1 addition & 0 deletions framework/chaos/chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func ExecPumba(command string) (func(), error) {
pumbaReq := testcontainers.ContainerRequest{
Name: fmt.Sprintf("chaos-%s", uuid.NewString()[0:5]),
Image: "gaiaadm/pumba",
Labels: framework.DefaultTCLabels(),
Privileged: true,
Cmd: cmd,
HostConfigModifier: func(h *container.HostConfig) {
Expand Down
44 changes: 37 additions & 7 deletions framework/components/clnode/clnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/postgres"
Expand Down Expand Up @@ -48,6 +49,8 @@ type NodeInput struct {
UserConfigOverrides string `toml:"user_config_overrides"`
TestSecretsOverrides string `toml:"test_secrets_overrides"`
UserSecretsOverrides string `toml:"user_secrets_overrides"`
HTTPPort int `toml:"port"`
P2PPort int `toml:"p2p_port"`
}

// Output represents Chainlink node output, nodes and databases connection URLs
Expand Down Expand Up @@ -166,6 +169,24 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
},
WaitingFor: wait.ForLog("Listening and serving HTTP").WithStartupTimeout(2 * time.Minute),
}
if in.Node.HTTPPort != 0 && in.Node.P2PPort != 0 {
req.HostConfigModifier = func(h *container.HostConfig) {
h.PortBindings = nat.PortMap{
"6688/tcp": []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: fmt.Sprintf("%d/tcp", in.Node.HTTPPort),
},
},
"6690/udp": []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostPort: fmt.Sprintf("%d/udp", in.Node.P2PPort),
},
},
}
}
}
files := []tc.ContainerFile{
{
HostFilePath: cfgPath.Name(),
Expand Down Expand Up @@ -242,13 +263,22 @@ func newNode(in *Input, pgOut *postgres.Output) (*NodeOut, error) {
if err != nil {
return nil, err
}
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
}
}

return &NodeOut{
Expand Down
66 changes: 5 additions & 61 deletions framework/components/simple_node_set/node_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func NewSharedDBNodeSet(in *Input, bcOut *blockchain.Output, fakeUrl string) (*O
}
switch in.OverrideMode {
case "all":
out, err = oneNodeSharedDBConfiguration(in, bcOut, fakeUrl, false)
out, err = sharedDBSetup(in, bcOut, fakeUrl, false)
if err != nil {
return nil, err
}
case "each":
out, err = oneNodeSharedDBConfiguration(in, bcOut, fakeUrl, true)
out, err = sharedDBSetup(in, bcOut, fakeUrl, true)
if err != nil {
return nil, err
}
Expand All @@ -59,65 +59,7 @@ func printOut(out *Output) {
}
}

// TODO: it seems we can use one DB for now
// TODO: remove
func NewNodeSet(in *Input, bcOut *blockchain.Output, fakeUrl string) (*Output, error) {
if in.Out != nil && in.Out.UseCache {
return in.Out, nil
}
nodeOuts := make([]*clnode.Output, 0)
eg := &errgroup.Group{}
mu := &sync.Mutex{}
for i := 0; i < in.Nodes; i++ {
i := i
eg.Go(func() error {
net, err := clnode.NewNetworkCfgOneNetworkAllNodes(bcOut)
if err != nil {
return err
}

nodeSpec := &clnode.Input{
DataProviderURL: fakeUrl,
DbInput: in.NodeSpecs[i].DbInput,
Node: &clnode.NodeInput{
Image: in.NodeSpecs[i].Node.Image,
Name: fmt.Sprintf("node%d", i),
PullImage: in.NodeSpecs[i].Node.PullImage,
CapabilitiesBinaryPaths: in.NodeSpecs[i].Node.CapabilitiesBinaryPaths,
CapabilityContainerDir: in.NodeSpecs[i].Node.CapabilityContainerDir,
TestConfigOverrides: net,
UserConfigOverrides: in.NodeSpecs[i].Node.UserConfigOverrides,
TestSecretsOverrides: in.NodeSpecs[i].Node.TestSecretsOverrides,
UserSecretsOverrides: in.NodeSpecs[i].Node.UserSecretsOverrides,
},
}

dbOut, err := postgres.NewPostgreSQL(in.NodeSpecs[i].DbInput)
if err != nil {
return err
}
o, err := clnode.NewNode(nodeSpec, dbOut)
if err != nil {
return err
}
mu.Lock()
nodeOuts = append(nodeOuts, o)
mu.Unlock()
return nil
})
}
if err := eg.Wait(); err != nil {
return nil, err
}
out := &Output{
UseCache: true,
CLNodes: nodeOuts,
}
in.Out = out
return out, nil
}

func oneNodeSharedDBConfiguration(in *Input, bcOut *blockchain.Output, fakeUrl string, overrideEach bool) (*Output, error) {
func sharedDBSetup(in *Input, bcOut *blockchain.Output, fakeUrl string, overrideEach bool) (*Output, error) {
dbOut, err := postgres.NewPostgreSQL(in.NodeSpecs[0].DbInput)
if err != nil {
return nil, err
Expand Down Expand Up @@ -147,6 +89,8 @@ func oneNodeSharedDBConfiguration(in *Input, bcOut *blockchain.Output, fakeUrl s
DataProviderURL: fakeUrl,
DbInput: in.NodeSpecs[overrideIdx].DbInput,
Node: &clnode.NodeInput{
HTTPPort: in.NodeSpecs[overrideIdx].Node.HTTPPort + i,
P2PPort: in.NodeSpecs[overrideIdx].Node.P2PPort + i,
Image: in.NodeSpecs[overrideIdx].Node.Image,
Name: nodeName,
PullImage: in.NodeSpecs[overrideIdx].Node.PullImage,
Expand Down
2 changes: 2 additions & 0 deletions framework/examples/myproject/load.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
[nodeset.node_specs.node]
image = "public.ecr.aws/chainlink/chainlink:v2.17.0"
pull_image = false
port = 5000
p2p_port = 5100
61 changes: 33 additions & 28 deletions framework/examples/myproject/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
"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 @@ -31,37 +29,44 @@ 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()
//}

c, err := clclient.NewCLDefaultClients(out.CLNodes, framework.L)
_, 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)
//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")
require.NoError(t, err)
_, err = chaos.ExecPumba("netem --tc-image=gaiadocker/iproute2 --duration=1m delay --time=300 re2:node.*")
time.Sleep(5 * time.Second)
_, err = clclient.NewCLDefaultClients(out.CLNodes, framework.L)
require.NoError(t, err)
p.Wait()

//p.Wait()
})
}

0 comments on commit 537aa52

Please sign in to comment.