Skip to content

Commit

Permalink
test/e2e: replace fixed sleeps with require.Eventually (#5975)
Browse files Browse the repository at this point in the history
Makes the endpoint slice E2E test faster and
less likely to flake.

Closes #5974.

Signed-off-by: Steve Kriss <krisss@vmware.com>
  • Loading branch information
skriss authored Nov 20, 2023
1 parent e370f45 commit c7cb2e2
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions test/e2e/infra/endpointslice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
package infra

import (
"time"
"slices"
"sort"

envoy_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -59,48 +60,53 @@ func testSimpleEndpointSlice(namespace string) {
},
}

f.CreateHTTPProxyAndWaitFor(p, e2e.HTTPProxyValid)
time.Sleep(time.Second * 10)
_, ok := f.CreateHTTPProxyAndWaitFor(p, e2e.HTTPProxyValid)
require.True(f.T(), ok)

k8sPodIPs, err := f.Fixtures.Echo.ListPodIPs(namespace, "echo")
require.NoError(f.T(), err)
envoyEndpoints, err := GetIPsFromAdminRequest()
require.NoError(f.T(), err)
require.ElementsMatch(f.T(), k8sPodIPs, envoyEndpoints)
require.Eventually(f.T(), func() bool {
return IsEnvoyProgrammedWithAllPodIPs(namespace)
}, f.RetryTimeout, f.RetryInterval)

// scale up to 10 pods
f.Fixtures.Echo.ScaleAndWaitDeployment("echo", namespace, 10)
// give time for changes to be propagated by envoy and contour
time.Sleep(time.Second * 10)
k8sPodIPs, err = f.Fixtures.Echo.ListPodIPs(namespace, "echo")
require.NoError(f.T(), err)
envoyEndpoints, err = GetIPsFromAdminRequest()
require.NoError(f.T(), err)
require.ElementsMatch(f.T(), k8sPodIPs, envoyEndpoints)

require.Eventually(f.T(), func() bool {
return IsEnvoyProgrammedWithAllPodIPs(namespace)
}, f.RetryTimeout, f.RetryInterval)

// scale down to 2 pods
f.Fixtures.Echo.ScaleAndWaitDeployment("echo", namespace, 2)
// give time for changes to be propagated by envoy and contour
time.Sleep(time.Second * 10)
k8sPodIPs, err = f.Fixtures.Echo.ListPodIPs(namespace, "echo")
require.NoError(f.T(), err)
envoyEndpoints, err = GetIPsFromAdminRequest()
require.NoError(f.T(), err)
require.ElementsMatch(f.T(), k8sPodIPs, envoyEndpoints)

require.Eventually(f.T(), func() bool {
return IsEnvoyProgrammedWithAllPodIPs(namespace)
}, f.RetryTimeout, f.RetryInterval)

// scale to 0
f.Fixtures.Echo.ScaleAndWaitDeployment("echo", namespace, 0)
// give time for changes to be propagated by envoy and contour
time.Sleep(time.Second * 10)
k8sPodIPs, err = f.Fixtures.Echo.ListPodIPs(namespace, "echo")
require.NoError(f.T(), err)
envoyEndpoints, err = GetIPsFromAdminRequest()
require.NoError(f.T(), err)
require.ElementsMatch(f.T(), k8sPodIPs, envoyEndpoints)

require.Eventually(f.T(), func() bool {
return IsEnvoyProgrammedWithAllPodIPs(namespace)
}, f.RetryTimeout, f.RetryInterval)
})
}

func IsEnvoyProgrammedWithAllPodIPs(namespace string) bool {
k8sPodIPs, err := f.Fixtures.Echo.ListPodIPs(namespace, "echo")
if err != nil {
return false
}

envoyEndpoints, err := GetIPsFromAdminRequest()
if err != nil {
return false
}

sort.Strings(k8sPodIPs)
sort.Strings(envoyEndpoints)

return slices.Equal(k8sPodIPs, envoyEndpoints)
}

// GetIPsFromAdminRequest makes a call to the envoy admin endpoint and parses
// all the IPs as a list from the echo cluster
func GetIPsFromAdminRequest() ([]string, error) {
Expand Down

0 comments on commit c7cb2e2

Please sign in to comment.