From f1b6158a6da730fdb1b2cb8edc8b8842cdab33a5 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Sun, 11 Oct 2015 12:58:56 +0200 Subject: [PATCH] Let port forwarding e2e tests timeout on kubectl calls --- test/e2e/portforward.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/test/e2e/portforward.go b/test/e2e/portforward.go index 4f34af22745..49f8c6c4232 100644 --- a/test/e2e/portforward.go +++ b/test/e2e/portforward.go @@ -24,8 +24,10 @@ import ( "regexp" "strconv" "strings" + "time" "k8s.io/kubernetes/pkg/api" + "k8s.io/kubernetes/pkg/util" . "github.com/onsi/ginkgo" ) @@ -110,6 +112,20 @@ func runPortForward(ns, podName string, port int) (*exec.Cmd, int) { return cmd, listenPort } +func runKubectlWithTimeout(timeout time.Duration, args ...string) string { + logOutput := make(chan string) + go func() { + logOutput <- runKubectl(args...) + }() + select { + case <-time.After(timeout): + Failf("kubectl timed out") + return "" + case o := <-logOutput: + return o + } +} + var _ = Describe("Port forwarding", func() { framework := NewFramework("port-forwarding") @@ -133,7 +149,7 @@ var _ = Describe("Port forwarding", func() { By("Closing the connection to the local port") conn.Close() - logOutput := runKubectl("logs", fmt.Sprintf("--namespace=%v", framework.Namespace.Name), "-f", podName) + logOutput := runKubectlWithTimeout(util.ForeverTestTimeout, "logs", fmt.Sprintf("--namespace=%v", framework.Namespace.Name), "-f", podName) verifyLogMessage(logOutput, "Accepted client connection") verifyLogMessage(logOutput, "Expected to read 3 bytes from client, but got 0 instead") }) @@ -178,7 +194,7 @@ var _ = Describe("Port forwarding", func() { Failf("Expected %q from server, got %q", e, a) } - logOutput := runKubectl("logs", fmt.Sprintf("--namespace=%v", framework.Namespace.Name), "-f", podName) + logOutput := runKubectlWithTimeout(util.ForeverTestTimeout, "logs", fmt.Sprintf("--namespace=%v", framework.Namespace.Name), "-f", podName) verifyLogMessage(logOutput, "^Accepted client connection$") verifyLogMessage(logOutput, "^Received expected client data$") verifyLogMessage(logOutput, "^Done$") @@ -215,7 +231,7 @@ var _ = Describe("Port forwarding", func() { Failf("Expected %q from server, got %q", e, a) } - logOutput := runKubectl("logs", fmt.Sprintf("--namespace=%v", framework.Namespace.Name), "-f", podName) + logOutput := runKubectlWithTimeout(util.ForeverTestTimeout, "logs", fmt.Sprintf("--namespace=%v", framework.Namespace.Name), "-f", podName) verifyLogMessage(logOutput, "Accepted client connection") verifyLogMessage(logOutput, "Done") })