Skip to content

Commit d70a469

Browse files
committed
finalize
1 parent 2b57a8a commit d70a469

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

framework/chaos/chaos.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ import (
99
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1010
"github.com/testcontainers/testcontainers-go"
1111
"strings"
12+
"time"
1213
)
1314

14-
func ExecPumba(command string) (func(), error) {
15+
// ExecPumba executes Pumba (https://github.com/alexei-led/pumba) command
16+
// since handling various docker race conditions is hard and there is no easy API for that
17+
// for now you can provide time to wait until chaos is applied
18+
func ExecPumba(command string, wait time.Duration) (func(), error) {
1519
ctx := context.Background()
1620
cmd := strings.Split(command, " ")
1721
pumbaReq := testcontainers.ContainerRequest{
@@ -38,7 +42,9 @@ func ExecPumba(command string) (func(), error) {
3842
if err != nil {
3943
return nil, fmt.Errorf("failed to start pumba chaos container: %w", err)
4044
}
41-
framework.L.Info().Msg("Pumba chaos started")
45+
framework.L.Info().Str("Cmd", command).Msg("Pumba chaos has started")
46+
time.Sleep(wait)
47+
framework.L.Info().Msg("Pumba chaos has finished")
4248
return func() {
4349
_ = pumbaContainer.Terminate(ctx)
4450
}, nil

framework/examples/myproject/chaos_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set"
1010
"github.com/stretchr/testify/require"
1111
"testing"
12+
"time"
1213
)
1314

1415
type CfgChaos struct {
@@ -35,7 +36,7 @@ func TestChaos(t *testing.T) {
3536
// example commands for Pumba:
3637
// stop --duration=1s --restart re2:node0 # stop one container for 1s and restart
3738
// netem --tc-image=gaiadocker/iproute2 --duration=1m delay --time=300 re2:node.* # slow network
38-
_, err = chaos.ExecPumba("stop --duration=1s --restart re2:node0")
39+
_, err = chaos.ExecPumba("stop --duration=1s --restart re2:node0", 1*time.Second)
3940
require.NoError(t, err)
4041
_, _, err = c[0].ReadBridges()
4142
require.NoError(t, err)

framework/examples/myproject/reload_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ func TestReload(t *testing.T) {
5151
fetch -> parse -> multiply -> encode_tx -> submit_tx
5252
"""`)
5353
require.NoError(t, err)
54-
time.Sleep(20 * time.Second)
5554

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

0 commit comments

Comments
 (0)