From 457c05feb87bfbf1ace9718eabeeb81d60f6bcb7 Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Fri, 21 Feb 2020 15:47:42 +0100 Subject: [PATCH] deflake e2e session affinity tests Executing commands in pods is expensive in terms of time and the execution time is unpredictable and random. The session affinity tests send several http requests from a pod to check that the session is sticky. Instead of executing one http request at a time, we can execute several requests from the pod at one time and process the output. --- test/e2e/network/service.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/e2e/network/service.go b/test/e2e/network/service.go index 7606f89e8a5..71a314f5b14 100644 --- a/test/e2e/network/service.go +++ b/test/e2e/network/service.go @@ -114,20 +114,26 @@ type portsByPodName map[string][]int // return false only in case of unexpected errors. func checkAffinity(execPod *v1.Pod, serviceIP string, servicePort int, shouldHold bool) bool { serviceIPPort := net.JoinHostPort(serviceIP, strconv.Itoa(servicePort)) - cmd := fmt.Sprintf(`curl -q -s --connect-timeout 2 http://%s/`, serviceIPPort) + curl := fmt.Sprintf(`curl -q -s --connect-timeout 2 http://%s/`, serviceIPPort) + cmd := fmt.Sprintf("for i in $(seq 0 %d); do echo; %s ; done", AffinityConfirmCount, curl) timeout := AffinityTimeout if execPod == nil { timeout = LoadBalancerPollTimeout } var tracker affinityTracker - if pollErr := wait.PollImmediate(framework.Poll, timeout, func() (bool, error) { + // interval considering a maximum of 2 seconds per connection + interval := 2 * AffinityConfirmCount * time.Second + if pollErr := wait.PollImmediate(interval, timeout, func() (bool, error) { if execPod != nil { stdout, err := framework.RunHostCmd(execPod.Namespace, execPod.Name, cmd) if err != nil { framework.Logf("Failed to get response from %s. Retry until timeout", serviceIPPort) return false, nil } - tracker.recordHost(stdout) + hosts := strings.Split(stdout, "\n") + for _, host := range hosts { + tracker.recordHost(strings.TrimSpace(host)) + } } else { rawResponse := GetHTTPContent(serviceIP, servicePort, timeout, "") tracker.recordHost(rawResponse.String())