Skip to content

Commit

Permalink
Keep trying for geth container start (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG authored Sep 7, 2023
1 parent c2c6e9c commit ab0f0b5
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 deletions.
15 changes: 15 additions & 0 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
tc "github.com/testcontainers/testcontainers-go"
)

const RetryAttempts = 3

func CreateNetwork() (*tc.DockerNetwork, error) {
uuidObj, _ := uuid.NewRandom()
var networkName = fmt.Sprintf("network-%s", uuidObj.String())
Expand All @@ -28,3 +30,16 @@ func CreateNetwork() (*tc.DockerNetwork, error) {
log.Trace().Any("network", dockerNetwork).Msgf("created network")
return dockerNetwork, nil
}

func StartContainerWithRetry(req tc.GenericContainerRequest) (tc.Container, error) {
var ct tc.Container
var err error
for i := 0; i < RetryAttempts; i++ {
ct, err = tc.GenericContainer(context.Background(), req)
if err == nil {
break
}
log.Error().Err(err).Msgf("Cannot start %s container, retrying %d/%d", req.Name, i+1, RetryAttempts)
}
return ct, err
}
15 changes: 8 additions & 7 deletions docker/test_env/geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
tcwait "github.com/testcontainers/testcontainers-go/wait"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/docker"
"github.com/smartcontractkit/chainlink-testing-framework/utils/templates"
)

Expand Down Expand Up @@ -62,12 +63,12 @@ func (g *Geth) StartContainer() (blockchain.EVMNetwork, InternalDockerUrls, erro
if err != nil {
return blockchain.EVMNetwork{}, InternalDockerUrls{}, err
}
ct, err := tc.GenericContainer(context.Background(),
tc.GenericContainerRequest{
ContainerRequest: *r,
Started: true,
Reuse: true,
})

ct, err := docker.StartContainerWithRetry(tc.GenericContainerRequest{
ContainerRequest: *r,
Reuse: true,
Started: true,
})
if err != nil {
return blockchain.EVMNetwork{}, InternalDockerUrls{}, errors.Wrapf(err, "cannot start geth container")
}
Expand Down Expand Up @@ -258,7 +259,7 @@ func NewWebSocketStrategy(port nat.Port) *WebSocketStrategy {
return &WebSocketStrategy{
Port: port,
RetryDelay: 10 * time.Second,
timeout: 5 * time.Minute,
timeout: 1 * time.Minute,
}
}

Expand Down
5 changes: 3 additions & 2 deletions docker/test_env/mockserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
tcwait "github.com/testcontainers/testcontainers-go/wait"

ctfClient "github.com/smartcontractkit/chainlink-testing-framework/client"
"github.com/smartcontractkit/chainlink-testing-framework/docker"
)

type MockServer struct {
Expand Down Expand Up @@ -60,10 +61,10 @@ func (ms *MockServer) SetExternalAdapterMocks(count int) error {
}

func (ms *MockServer) StartContainer() error {
c, err := tc.GenericContainer(context.Background(), tc.GenericContainerRequest{
c, err := docker.StartContainerWithRetry(tc.GenericContainerRequest{
ContainerRequest: ms.getContainerRequest(),
Started: true,
Reuse: true,
Started: true,
})
if err != nil {
return errors.Wrapf(err, "cannot start MockServer container")
Expand Down
23 changes: 11 additions & 12 deletions docker/test_env/non_dev_geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
tcwait "github.com/testcontainers/testcontainers-go/wait"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/docker"
"github.com/smartcontractkit/chainlink-testing-framework/utils/templates"
)

Expand Down Expand Up @@ -200,12 +201,11 @@ func (g *NonDevGethNode) Start() error {
if err != nil {
return err
}
bootNode, err := tc.GenericContainer(context.Background(),
tc.GenericContainerRequest{
ContainerRequest: g.getBootNodeContainerRequest(),
Started: true,
Reuse: true,
})
bootNode, err := docker.StartContainerWithRetry(tc.GenericContainerRequest{
ContainerRequest: g.getBootNodeContainerRequest(),
Reuse: true,
Started: true,
})
if err != nil {
return err
}
Expand All @@ -224,12 +224,11 @@ func (g *NonDevGethNode) Start() error {
}
g.Config.bootNodeURL = fmt.Sprintf("enode://%s@%s:0?discport=%s", strings.TrimSpace(string(b)), host, BOOTNODE_PORT)

ct, err := tc.GenericContainer(context.Background(),
tc.GenericContainerRequest{
ContainerRequest: g.getGethContainerRequest(),
Started: true,
Reuse: true,
})
ct, err := docker.StartContainerWithRetry(tc.GenericContainerRequest{
ContainerRequest: g.getGethContainerRequest(),
Reuse: true,
Started: true,
})
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ require (
github.com/hashicorp/memberlist v0.5.0 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand Down Expand Up @@ -245,7 +245,7 @@ require (
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/tools v0.9.1 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230526161137-0005af68ea54 // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,8 @@ github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfE
github.com/hetznercloud/hcloud-go v1.41.0 h1:KJGFRRc68QiVu4PrEP5BmCQVveCP2CM26UGQUKGpIUs=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c h1:DZfsyhDK1hnSS5lH8l+JggqzEleHteTYfutAiVlSUM8=
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o=
github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huin/goupnp v1.0.3 h1:N8No57ls+MnjlB+JPiCVSOyy/ot7MJTqlo7rn+NYSqQ=
github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
Expand Down Expand Up @@ -2102,8 +2102,9 @@ golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo=
golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down

0 comments on commit ab0f0b5

Please sign in to comment.