Skip to content

Commit 457c05f

Browse files
committed
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.
1 parent ac25069 commit 457c05f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

test/e2e/network/service.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,26 @@ type portsByPodName map[string][]int
114114
// return false only in case of unexpected errors.
115115
func checkAffinity(execPod *v1.Pod, serviceIP string, servicePort int, shouldHold bool) bool {
116116
serviceIPPort := net.JoinHostPort(serviceIP, strconv.Itoa(servicePort))
117-
cmd := fmt.Sprintf(`curl -q -s --connect-timeout 2 http://%s/`, serviceIPPort)
117+
curl := fmt.Sprintf(`curl -q -s --connect-timeout 2 http://%s/`, serviceIPPort)
118+
cmd := fmt.Sprintf("for i in $(seq 0 %d); do echo; %s ; done", AffinityConfirmCount, curl)
118119
timeout := AffinityTimeout
119120
if execPod == nil {
120121
timeout = LoadBalancerPollTimeout
121122
}
122123
var tracker affinityTracker
123-
if pollErr := wait.PollImmediate(framework.Poll, timeout, func() (bool, error) {
124+
// interval considering a maximum of 2 seconds per connection
125+
interval := 2 * AffinityConfirmCount * time.Second
126+
if pollErr := wait.PollImmediate(interval, timeout, func() (bool, error) {
124127
if execPod != nil {
125128
stdout, err := framework.RunHostCmd(execPod.Namespace, execPod.Name, cmd)
126129
if err != nil {
127130
framework.Logf("Failed to get response from %s. Retry until timeout", serviceIPPort)
128131
return false, nil
129132
}
130-
tracker.recordHost(stdout)
133+
hosts := strings.Split(stdout, "\n")
134+
for _, host := range hosts {
135+
tracker.recordHost(strings.TrimSpace(host))
136+
}
131137
} else {
132138
rawResponse := GetHTTPContent(serviceIP, servicePort, timeout, "")
133139
tracker.recordHost(rawResponse.String())

0 commit comments

Comments
 (0)