From 8771eae0ae69bc04ead9d9fa0fd6759f6ae9775c Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Wed, 7 Nov 2018 16:40:45 -0800 Subject: [PATCH] testDashboard: add timeout around reading URL from stdout. This test typically takes <30s to execute, so 180s should leave plenty of margin for error. --- test/integration/addons_test.go | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index 208bad7c22..5f735cfdb9 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -19,6 +19,7 @@ limitations under the License. package integration import ( + "bufio" "fmt" "io/ioutil" "net" @@ -46,19 +47,45 @@ func testAddons(t *testing.T) { } } +func readLineWithTimeout(b *bufio.Reader, timeout time.Duration) (string, error) { + s := make(chan string) + e := make(chan error) + go func() { + read, err := b.ReadString('\n') + if err != nil { + e <- err + } else { + s <- read + } + close(s) + close(e) + }() + + select { + case line := <-s: + return line, nil + case err := <-e: + return "", err + case <-time.After(timeout): + return "", fmt.Errorf("timeout after %s", timeout) + } +} + func testDashboard(t *testing.T) { t.Parallel() minikubeRunner := NewMinikubeRunner(t) - + t.Logf("Launching dashboard ...") cmd, out := minikubeRunner.RunDaemon("dashboard --url") defer func() { + t.Logf("Killing dashboard ...") err := cmd.Process.Kill() if err != nil { - t.Logf("Failed to kill mount command: %v", err) + t.Logf("Failed to kill dashboard command: %v", err) } }() - s, err := out.ReadString('\n') + t.Logf("Waiting for URL to be output by minikube dashboard...") + s, err := readLineWithTimeout(out, 180*time.Second) if err != nil { t.Fatalf("failed to read url: %v", err) }