Skip to content

Commit 39a5664

Browse files
balopatdgageot
authored andcommitted
Fix portforward flake (#2824)
* change logging to test logging * better logging + decreased timeout in case stalled connection
1 parent 02509f7 commit 39a5664

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

integration/dev_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"testing"
2727
"time"
2828

29-
"github.com/sirupsen/logrus"
3029
"k8s.io/apimachinery/pkg/util/wait"
3130
"k8s.io/client-go/tools/clientcmd"
3231

@@ -306,7 +305,8 @@ func waitForPortForwardEvent(t *testing.T, entries chan *proto.LogEntry, resourc
306305

307306
// assertResponseFromPort waits for two minutes for the expected response at port.
308307
func assertResponseFromPort(t *testing.T, port int, expected string) {
309-
logrus.Infof("Waiting for response %s from port %d", expected, port)
308+
url := fmt.Sprintf("http://%s:%d", util.Loopback, port)
309+
t.Logf("Waiting on %s to return: %s", url, expected)
310310
ctx, cancelTimeout := context.WithTimeout(context.Background(), 2*time.Minute)
311311
defer cancelTimeout()
312312

@@ -315,21 +315,22 @@ func assertResponseFromPort(t *testing.T, port int, expected string) {
315315
case <-ctx.Done():
316316
t.Fatalf("Timed out waiting for response from port %d", port)
317317
case <-time.After(1 * time.Second):
318-
resp, err := http.Get(fmt.Sprintf("http://%s:%d", util.Loopback, port))
318+
client := http.Client{Timeout: 1 * time.Second}
319+
resp, err := client.Get(url)
319320
if err != nil {
320-
logrus.Infof("error getting response from port %d: %v", port, err)
321+
t.Logf("[retriable error]: %v", err)
321322
continue
322323
}
323324
defer resp.Body.Close()
324325
body, err := ioutil.ReadAll(resp.Body)
325326
if err != nil {
326-
logrus.Infof("error reading response: %v", err)
327+
t.Logf("[retriable error] reading response: %v", err)
327328
continue
328329
}
329330
if string(body) == expected {
330331
return
331332
}
332-
logrus.Infof("didn't get expected response from port. got: %s, expected: %s", string(body), expected)
333+
t.Logf("[retriable error] didn't get expected response from port. got: %s, expected: %s", string(body), expected)
333334
}
334335
}
335336
}

0 commit comments

Comments
 (0)