mirror of https://github.com/status-im/consul.git
test: container tests wait for available networks (#16045)
This commit is contained in:
parent
7b3b0f469b
commit
96389eb266
|
@ -37,6 +37,7 @@ type Cluster struct {
|
|||
}
|
||||
|
||||
type TestingT interface {
|
||||
Logf(format string, args ...any)
|
||||
Cleanup(f func())
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,15 @@ package cluster
|
|||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
)
|
||||
|
||||
const tooManyNetworksError = "could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network: failed to create network"
|
||||
|
||||
func createNetwork(t TestingT, name string) (testcontainers.Network, error) {
|
||||
req := testcontainers.GenericNetworkRequest{
|
||||
NetworkRequest: testcontainers.NetworkRequest{
|
||||
|
@ -15,12 +19,23 @@ func createNetwork(t TestingT, name string) (testcontainers.Network, error) {
|
|||
CheckDuplicate: true,
|
||||
},
|
||||
}
|
||||
first := true
|
||||
RETRY:
|
||||
network, err := testcontainers.GenericNetwork(context.Background(), req)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), tooManyNetworksError) {
|
||||
if first {
|
||||
t.Logf("waiting until possible to get a network")
|
||||
first = false
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
goto RETRY
|
||||
}
|
||||
return nil, errors.Wrap(err, "could not create network")
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
_ = network.Remove(context.Background())
|
||||
})
|
||||
|
||||
return network, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue