Skip to content

Commit 9e87e99

Browse files
committed
Add timeout for port-forward test
After removing a pod in port-forward test we wait for an error from POST request. Since the POST doesn't have a timeout it hangs indefinitely, so instead we're hitting a DefaultPodDeletionTimeout. To make sure the POST fails this adds a timeout to ensure we'll always get that expected error, rather than nil. Signed-off-by: Maciej Szulik <[email protected]>
1 parent 475ee33 commit 9e87e99

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

test/e2e/kubectl/portforward.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ var _ = SIGDescribe("Kubectl Port forwarding", func() {
587587
for sentBodySize := 0; sentBodySize < 1024*1024*1024; {
588588
size := rand.Intn(4 * 1024 * 1024)
589589
url := fmt.Sprintf("http://localhost:%d/header", cmd.port)
590-
_, err := post(url, strings.NewReader(strings.Repeat("x", size)), nil)
590+
_, err := post(url, strings.NewReader(strings.Repeat("x", size)), 10*time.Second)
591591
if err != nil {
592592
errorChan <- err
593593
}
@@ -611,7 +611,10 @@ var _ = SIGDescribe("Kubectl Port forwarding", func() {
611611

612612
ginkgo.By("Check the client error")
613613
gomega.Expect(err).To(gomega.HaveOccurred())
614-
gomega.Expect(err.Error()).To(gomega.Or(gomega.ContainSubstring("connection reset by peer"), gomega.ContainSubstring("EOF")))
614+
gomega.Expect(err.Error()).To(gomega.Or(
615+
gomega.ContainSubstring("connection reset by peer"),
616+
gomega.ContainSubstring("EOF"),
617+
gomega.ContainSubstring("context deadline exceeded")))
615618

616619
ginkgo.By("Check kubectl port-forward exit code")
617620
gomega.Expect(cmd.cmd.ProcessState.ExitCode()).To(gomega.BeNumerically("<", 0), "kubectl port-forward should finish with non-zero exit code")
@@ -695,11 +698,11 @@ func wsWrite(conn *websocket.Conn, channel byte, data []byte) error {
695698
return err
696699
}
697700

698-
func post(url string, reader io.Reader, transport *http.Transport) (string, error) {
699-
if transport == nil {
700-
transport = utilnet.SetTransportDefaults(&http.Transport{})
701+
func post(url string, reader io.Reader, timeout time.Duration) (string, error) {
702+
client := &http.Client{
703+
Transport: utilnet.SetTransportDefaults(&http.Transport{}),
704+
Timeout: timeout,
701705
}
702-
client := &http.Client{Transport: transport}
703706
req, err := http.NewRequest(http.MethodPost, url, reader)
704707
if err != nil {
705708
return "", err

0 commit comments

Comments
 (0)