Skip to content

Commit

Permalink
Retry port-forward on failure (hashicorp#725)
Browse files Browse the repository at this point in the history
The port-forward sometimes fails randomly
  • Loading branch information
lkysow authored Dec 2, 2020
1 parent 146833a commit 3ae0369
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/acceptance/framework/consul/consul_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"
"testing"
"time"

"github.com/gruntwork-io/terratest/modules/helm"
terratestk8s "github.com/gruntwork-io/terratest/modules/k8s"
Expand All @@ -16,6 +17,7 @@ import (
"github.com/hashicorp/consul-helm/test/acceptance/framework/k8s"
"github.com/hashicorp/consul-helm/test/acceptance/framework/logger"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/sdk/testutil/retry"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -223,7 +225,14 @@ func (h *HelmCluster) SetupConsulClient(t *testing.T, secure bool) *api.Client {
localPort,
remotePort,
h.logger)
tunnel.ForwardPort(t)

// Retry creating the port forward since it can fail occasionally.
retry.RunWith(&retry.Counter{Wait: 1 * time.Second, Count: 3}, t, func(r *retry.R) {
// NOTE: It's okay to pass in `t` to ForwardPortE despite being in a retry
// because we're using ForwardPortE (not ForwardPort) so the `t` won't
// get used to fail the test, just for logging.
require.NoError(r, tunnel.ForwardPortE(t))
})

t.Cleanup(func() {
tunnel.Close()
Expand Down

0 comments on commit 3ae0369

Please sign in to comment.