Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let port forwarding e2e tests timeout on kubectl calls #15445

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 19 additions & 3 deletions test/e2e/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
"regexp"
"strconv"
"strings"
"time"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util"

. "github.com/onsi/ginkgo"
)
Expand Down Expand Up @@ -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")

Expand All @@ -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")
})
Expand Down Expand Up @@ -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$")
Expand Down Expand Up @@ -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")
})
Expand Down