Skip to content

Commit f668db9

Browse files
committed
try load + chaos in CI
1 parent d7c6f8a commit f668db9

File tree

6 files changed

+171
-62
lines changed

6 files changed

+171
-62
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Framework Golden Tests Examples
2+
on:
3+
push:
4+
concurrency:
5+
group: ${{ github.workflow }}-${{ github.ref }}-framework-golden-examples
6+
cancel-in-progress: true
7+
jobs:
8+
test:
9+
defaults:
10+
run:
11+
working-directory: framework/examples/myproject
12+
runs-on: ubuntu-latest
13+
permissions:
14+
id-token: write
15+
contents: read
16+
steps:
17+
- name: Checkout repo
18+
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
19+
- name: Configure AWS credentials using OIDC
20+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
21+
with:
22+
role-to-assume: ${{ secrets.PUBLIC_AWS_ECR_ROLE }}
23+
aws-region: us-east-1
24+
- name: Authenticate to ECR Public
25+
id: login-ecr-public
26+
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1
27+
with:
28+
registry-type: public
29+
- name: Check for changes in Framework
30+
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
31+
id: changes
32+
with:
33+
filters: |
34+
src:
35+
- 'framework/**'
36+
- name: Set up Go
37+
uses: actions/setup-go@v4
38+
with:
39+
go-version: 1.22.8
40+
- name: Cache Go modules
41+
uses: actions/cache@v3
42+
with:
43+
path: |
44+
~/.cache/go-build
45+
~/go/pkg/mod
46+
key: go-modules-${{ hashFiles('**/go.sum') }}-${{ runner.os }}-framework-golden-examples
47+
restore-keys: |
48+
go-modules-${{ hashFiles('**/go.sum') }}-${{ runner.os }}-framework-golden-examples
49+
- name: Install dependencies
50+
run: go mod download
51+
- name: Run Docker Component Tests
52+
if: steps.changes.outputs.src == 'true'
53+
run: |
54+
go test -timeout 5m -v -count 1 -run TestLoad

framework/chaos/chaos.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package chaos
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"github.com/docker/docker/api/types/container"
7+
"github.com/docker/docker/api/types/mount"
8+
"github.com/google/uuid"
9+
"github.com/smartcontractkit/chainlink-testing-framework/framework"
10+
"github.com/testcontainers/testcontainers-go"
11+
"strings"
12+
)
13+
14+
func NewPumbaChaos(command string) (func(), error) {
15+
ctx := context.Background()
16+
cmd := strings.Split(command, " ")
17+
pumbaReq := testcontainers.ContainerRequest{
18+
Name: fmt.Sprintf("chaos-%s", uuid.NewString()[0:5]),
19+
Image: "gaiaadm/pumba",
20+
Privileged: true,
21+
Cmd: cmd,
22+
HostConfigModifier: func(h *container.HostConfig) {
23+
h.Mounts = []mount.Mount{
24+
{
25+
Type: "bind",
26+
Source: "/var/run/docker.sock",
27+
Target: "/var/run/docker.sock",
28+
ReadOnly: true,
29+
},
30+
}
31+
},
32+
}
33+
pumbaContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
34+
ContainerRequest: pumbaReq,
35+
Started: true,
36+
})
37+
if err != nil {
38+
return nil, fmt.Errorf("failed to start pumba chaos container: %w", err)
39+
}
40+
framework.L.Info().Msg("Pumba chaos started")
41+
return func() {
42+
_ = pumbaContainer.Terminate(ctx)
43+
}, nil
44+
}

framework/examples/myproject/go.mod

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ replace (
88
)
99

1010
require (
11-
github.com/go-resty/resty/v2 v2.15.3
1211
github.com/smartcontractkit/chainlink-testing-framework/framework v0.1.9
1312
github.com/smartcontractkit/chainlink-testing-framework/wasp v1.50.2
1413
github.com/stretchr/testify v1.9.0
@@ -72,8 +71,9 @@ require (
7271
github.com/dustin/go-humanize v1.0.1 // indirect
7372
github.com/edsrzf/mmap-go v1.1.0 // indirect
7473
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
74+
github.com/ethereum/go-ethereum v1.14.11 // indirect
7575
github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb // indirect
76-
github.com/fatih/color v1.15.0 // indirect
76+
github.com/fatih/color v1.16.0 // indirect
7777
github.com/felixge/httpsnoop v1.0.4 // indirect
7878
github.com/fsnotify/fsnotify v1.6.0 // indirect
7979
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
@@ -98,6 +98,7 @@ require (
9898
github.com/go-playground/universal-translator v0.18.1 // indirect
9999
github.com/go-playground/validator/v10 v10.22.1 // indirect
100100
github.com/go-redis/redis/v8 v8.11.5 // indirect
101+
github.com/go-resty/resty/v2 v2.15.3 // indirect
101102
github.com/goccy/go-json v0.10.3 // indirect
102103
github.com/gogo/googleapis v1.4.1 // indirect
103104
github.com/gogo/protobuf v1.3.2 // indirect
@@ -129,6 +130,7 @@ require (
129130
github.com/hashicorp/golang-lru v0.6.0 // indirect
130131
github.com/hashicorp/memberlist v0.5.0 // indirect
131132
github.com/hashicorp/serf v0.10.1 // indirect
133+
github.com/holiman/uint256 v1.3.1 // indirect
132134
github.com/huandu/xstrings v1.3.3 // indirect
133135
github.com/imdario/mergo v0.3.16 // indirect
134136
github.com/jmespath/go-jmespath v0.4.0 // indirect
@@ -220,7 +222,7 @@ require (
220222
go4.org/netipx v0.0.0-20230125063823-8449b0a6169f // indirect
221223
golang.org/x/arch v0.11.0 // indirect
222224
golang.org/x/crypto v0.28.0 // indirect
223-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
225+
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
224226
golang.org/x/mod v0.17.0 // indirect
225227
golang.org/x/net v0.30.0 // indirect
226228
golang.org/x/oauth2 v0.23.0 // indirect
@@ -234,6 +236,7 @@ require (
234236
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
235237
google.golang.org/grpc v1.67.1 // indirect
236238
google.golang.org/protobuf v1.35.1 // indirect
239+
gopkg.in/guregu/null.v4 v4.0.0 // indirect
237240
gopkg.in/inf.v0 v0.9.1 // indirect
238241
gopkg.in/yaml.v2 v2.4.0 // indirect
239242
gopkg.in/yaml.v3 v3.0.1 // indirect

framework/examples/myproject/go.sum

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,15 @@ github.com/envoyproxy/go-control-plane v0.13.0/go.mod h1:GRaKG3dwvFoTg4nj7aXdZnv
226226
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
227227
github.com/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6Uu2PdjCQwWCJ3bM=
228228
github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4=
229+
github.com/ethereum/go-ethereum v1.14.11 h1:8nFDCUUE67rPc6AKxFj7JKaOa2W/W1Rse3oS6LvvxEY=
230+
github.com/ethereum/go-ethereum v1.14.11/go.mod h1:+l/fr42Mma+xBnhefL/+z11/hcmJ2egl+ScIVPjhc7E=
229231
github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb h1:IT4JYU7k4ikYg1SCxNI1/Tieq/NFvh6dzLdgi7eu0tM=
230232
github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb/go.mod h1:bH6Xx7IW64qjjJq8M2u4dxNaBiDfKK+z/3eGDpXEQhc=
231233
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
232234
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
233235
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
234-
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
235-
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
236+
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
237+
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
236238
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
237239
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
238240
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
@@ -508,6 +510,8 @@ github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY
508510
github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4=
509511
github.com/hetznercloud/hcloud-go/v2 v2.0.0 h1:Sg1DJ+MAKvbYAqaBaq9tPbwXBS2ckPIaMtVdUjKu+4g=
510512
github.com/hetznercloud/hcloud-go/v2 v2.0.0/go.mod h1:4iUG2NG8b61IAwNx6UsMWQ6IfIf/i1RsG0BbsKAyR5Q=
513+
github.com/holiman/uint256 v1.3.1 h1:JfTzmih28bittyHM8z360dCjIA9dbPIBlcTI6lmctQs=
514+
github.com/holiman/uint256 v1.3.1/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
511515
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
512516
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
513517
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
@@ -902,8 +906,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
902906
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
903907
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
904908
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
905-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
906-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
909+
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ=
910+
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE=
907911
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
908912
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
909913
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@@ -1236,6 +1240,8 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8
12361240
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
12371241
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
12381242
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
1243+
gopkg.in/guregu/null.v4 v4.0.0 h1:1Wm3S1WEA2I26Kq+6vcW+w0gcDo44YKYD7YIEJNHDjg=
1244+
gopkg.in/guregu/null.v4 v4.0.0/go.mod h1:YoQhUrADuG3i9WqesrCmpNRwm1ypAgSHYqoOcTu/JrI=
12391245
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
12401246
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
12411247
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,45 @@
11
package examples
22

33
import (
4-
"github.com/go-resty/resty/v2"
4+
"github.com/smartcontractkit/chainlink-testing-framework/framework/clclient"
55
"github.com/smartcontractkit/chainlink-testing-framework/wasp"
66
)
77

8-
type ExampleGun struct {
9-
target string
10-
client *resty.Client
8+
type CLNodeGun struct {
9+
Mode string
10+
client *clclient.ChainlinkClient
1111
Data []string
1212
}
1313

14-
func NewExampleHTTPGun(target string) *ExampleGun {
15-
return &ExampleGun{
16-
client: resty.New(),
17-
target: target,
14+
func NewCLNodeGun(c *clclient.ChainlinkClient, mode string) *CLNodeGun {
15+
return &CLNodeGun{
16+
Mode: mode,
17+
client: c,
1818
Data: make([]string, 0),
1919
}
2020
}
2121

2222
// Call implements example gun call, assertions on response bodies should be done here
23-
func (m *ExampleGun) Call(l *wasp.Generator) *wasp.Response {
24-
var result map[string]interface{}
25-
r, err := m.client.R().
26-
SetResult(&result).
27-
Get(m.target)
23+
func (m *CLNodeGun) Call(l *wasp.Generator) *wasp.Response {
24+
switch m.Mode {
25+
case "bridges":
26+
return m.bridges()
27+
default:
28+
panic("uknown generator mode")
29+
}
30+
return nil
31+
}
32+
33+
func (m *CLNodeGun) bridges() *wasp.Response {
34+
b, rr, err := m.client.ReadBridges()
35+
if b == nil {
36+
return &wasp.Response{Error: "bridges response is nil"}
37+
}
2838
if err != nil {
29-
return &wasp.Response{Data: result, Error: err.Error()}
39+
return &wasp.Response{Error: err.Error(), Failed: true}
3040
}
31-
if r.Status() != "200 OK" {
32-
return &wasp.Response{Data: result, Error: "not 200"}
41+
if rr.Status() != "200 OK" {
42+
return &wasp.Response{Error: "not 200", Failed: true}
3343
}
34-
return &wasp.Response{Data: result}
44+
return &wasp.Response{Data: b}
3545
}
Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package examples
22

33
import (
4-
"fmt"
54
"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"
67
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
78
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake"
89
ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set"
@@ -13,56 +14,47 @@ import (
1314
)
1415

1516
type CfgLoad struct {
16-
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
17-
//Contracts *onchain.Input `toml:"contracts" validate:"required"`
18-
MockerDataProvider *fake.Input `toml:"data_provider" validate:"required"`
19-
NodeSet *ns.Input `toml:"nodeset" validate:"required"`
17+
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
18+
MockerDataProvider *fake.Input `toml:"data_provider" validate:"required"`
19+
NodeSet *ns.Input `toml:"nodeset" validate:"required"`
2020
}
2121

2222
func TestLoad(t *testing.T) {
2323
in, err := framework.Load[CfgLoad](t)
2424
require.NoError(t, err)
25-
//pkey := os.Getenv("PRIVATE_KEY")
2625

2726
bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA)
2827
require.NoError(t, err)
2928
dp, err := fake.NewFakeDataProvider(in.MockerDataProvider)
3029
require.NoError(t, err)
31-
_, err = ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker)
30+
out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker)
3231
require.NoError(t, err)
3332

34-
//// deploy product contracts
35-
//in.Contracts.URL = bc.Nodes[0].HostWSUrl
36-
//contracts, err := onchain.NewProductOnChainDeployment(in.Contracts)
37-
//require.NoError(t, err)
38-
//
39-
//sc, err := seth.NewClientBuilder().
40-
// WithRpcUrl(bc.Nodes[0].HostWSUrl).
41-
// WithGasPriceEstimations(true, 0, seth.Priority_Fast).
42-
// WithTracing(seth.TracingLevel_All, []string{seth.TraceOutput_Console}).
43-
// WithPrivateKeys([]string{pkey}).
44-
// Build()
45-
//require.NoError(t, err)
33+
c, err := clclient.NewCLDefaultClients(out.CLNodes, framework.L)
34+
require.NoError(t, err)
4635

47-
t.Run("test something", func(t *testing.T) {
48-
labels := map[string]string{
49-
"go_test_name": "generator_healthcheck",
50-
"gen_name": "generator_healthcheck",
51-
"branch": "generator_healthcheck",
52-
"commit": "generator_healthcheck",
53-
}
54-
gen, err := wasp.NewGenerator(&wasp.Config{
55-
LoadType: wasp.RPS,
56-
Schedule: wasp.Combine(
57-
wasp.Steps(1, 1, 9, 30*time.Second),
58-
wasp.Plain(10, 30*time.Second),
59-
wasp.Steps(10, -1, 10, 30*time.Second),
60-
),
61-
Gun: NewExampleHTTPGun(fmt.Sprintf("%s/mock1", dp.BaseURLHost)),
62-
Labels: labels,
63-
LokiConfig: wasp.NewEnvLokiConfig(),
64-
})
36+
t.Run("run the cluster and simulate slow network", func(t *testing.T) {
37+
p, err := wasp.NewProfile().
38+
Add(wasp.NewGenerator(&wasp.Config{
39+
T: t,
40+
LoadType: wasp.RPS,
41+
Schedule: wasp.Combine(
42+
wasp.Steps(1, 1, 9, 30*time.Second),
43+
wasp.Plain(10, 30*time.Second),
44+
wasp.Steps(10, -1, 10, 30*time.Second),
45+
),
46+
Gun: NewCLNodeGun(c[0], "bridges"),
47+
Labels: map[string]string{
48+
"gen_name": "cl_node_api_call",
49+
"branch": "example",
50+
"commit": "example",
51+
},
52+
LokiConfig: wasp.NewEnvLokiConfig(),
53+
})).
54+
Run(false)
55+
require.NoError(t, err)
56+
_, err = chaos.NewPumbaChaos("netem --tc-image=gaiadocker/iproute2 --duration=1m delay --time=300 re2:node.*")
6557
require.NoError(t, err)
66-
gen.Run(true)
58+
p.Wait()
6759
})
6860
}

0 commit comments

Comments
 (0)