Skip to content

Commit

Permalink
finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov committed Nov 7, 2024
1 parent 2b57a8a commit d70a469
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions framework/chaos/chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import (
"github.com/smartcontractkit/chainlink-testing-framework/framework"
"github.com/testcontainers/testcontainers-go"
"strings"
"time"
)

func ExecPumba(command string) (func(), error) {
// ExecPumba executes Pumba (https://github.com/alexei-led/pumba) command
// since handling various docker race conditions is hard and there is no easy API for that
// for now you can provide time to wait until chaos is applied
func ExecPumba(command string, wait time.Duration) (func(), error) {
ctx := context.Background()
cmd := strings.Split(command, " ")
pumbaReq := testcontainers.ContainerRequest{
Expand All @@ -38,7 +42,9 @@ func ExecPumba(command string) (func(), error) {
if err != nil {
return nil, fmt.Errorf("failed to start pumba chaos container: %w", err)
}
framework.L.Info().Msg("Pumba chaos started")
framework.L.Info().Str("Cmd", command).Msg("Pumba chaos has started")
time.Sleep(wait)
framework.L.Info().Msg("Pumba chaos has finished")
return func() {
_ = pumbaContainer.Terminate(ctx)
}, nil
Expand Down
3 changes: 2 additions & 1 deletion framework/examples/myproject/chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set"
"github.com/stretchr/testify/require"
"testing"
"time"
)

type CfgChaos struct {
Expand All @@ -35,7 +36,7 @@ func TestChaos(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=1s --restart re2:node0")
_, err = chaos.ExecPumba("stop --duration=1s --restart re2:node0", 1*time.Second)
require.NoError(t, err)
_, _, err = c[0].ReadBridges()
require.NoError(t, err)
Expand Down
3 changes: 1 addition & 2 deletions framework/examples/myproject/reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ func TestReload(t *testing.T) {
fetch -> parse -> multiply -> encode_tx -> submit_tx
"""`)
require.NoError(t, err)
time.Sleep(20 * time.Second)

// deploy second time
_, err = chaos.ExecPumba("rm --volumes=false re2:node.*|postgresql.*")
_, err = chaos.ExecPumba("rm --volumes=false re2:node.*|postgresql.*", 1*time.Second)
require.NoError(t, err)
ns.UpdateNodeConfigs(in.NodeSet, `
[Log]
Expand Down

0 comments on commit d70a469

Please sign in to comment.