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

Test(e2e): List entities instead of dump.Get to fetch Kong config in e2e tests #6358

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion test/e2e/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,5 @@ func ensureAllProxyReplicasAreConfigured(ctx context.Context, t *testing.T, env
t.Logf("proxy pod %s/%s: got the config", pod.Namespace, pod.Name)
}()
}

wg.Wait()
}
46 changes: 31 additions & 15 deletions test/e2e/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/blang/semver/v4"
"github.com/google/uuid"
"github.com/kong/go-database-reconciler/pkg/dump"
"github.com/kong/go-kong/kong"
"github.com/kong/kubernetes-testing-framework/pkg/clusters"
ktfkong "github.com/kong/kubernetes-testing-framework/pkg/clusters/addons/kong"
Expand Down Expand Up @@ -528,31 +527,48 @@ func verifyIngressWithEchoBackendsInAdminAPI(
t.Helper()

require.Eventually(t, func() bool {
d, err := dump.Get(ctx, kongClient, dump.Config{})
start := time.Now()
defer func() {
t.Logf("Fetched config from %q, started at %s, duration %v", kongClient.BaseRootURL(), start.Format(time.RFC3339), time.Since(start))
}()

services, err := kongClient.Services.ListAll(ctx)
if err != nil {
t.Logf("failed dumping config: %s", err)
t.Logf("failed to list services: %v", err)
return false
}
if len(d.Services) != 1 {
t.Log("still no service found...")
if len(services) != 1 || services[0].ID == nil {
t.Logf("%d services found, expected 1", len(services))
return false
}
if len(d.Routes) != 1 {
t.Log("still no route found...")

routes, _, err := kongClient.Routes.ListForService(ctx, services[0].ID, &kong.ListOpt{})
if err != nil {
t.Logf("failed to list routes for service %s: %v", *services[0].ID, err)
return false
}
if d.Services[0].ID == nil ||
d.Routes[0].Service.ID == nil ||
*d.Services[0].ID != *d.Routes[0].Service.ID {
t.Log("still no matching service found...")
if len(routes) != 1 {
t.Logf("%d routes found under service %s, expected 1", len(routes), *services[0].ID)
return false
}
if len(d.Targets) != noReplicas {
t.Log("still no target found...")

upstreams, err := kongClient.Upstreams.ListAll(ctx)
if err != nil {
t.Logf("failed to list upstreams: %v", err)
return false
}
if len(upstreams) != 1 || upstreams[0].ID == nil {
t.Logf("%d upstreams found, expected 1", len(upstreams))
return false
}

targets, err := kongClient.Targets.ListAll(ctx, upstreams[0].ID)
if err != nil {
t.Logf("failed to list targets for upstream %s: %v", *upstreams[0].ID, err)
return false
}
if len(d.Upstreams) != 1 {
t.Log("still no upstream found...")
if len(targets) != noReplicas {
t.Logf("%d targets found, expected %d", len(targets), noReplicas)
return false
}
return true
Expand Down
5 changes: 2 additions & 3 deletions test/helpers/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@ func GetFreePort(t *testing.T) int {
freePort int
retriesLeft = 100
)
freePortLock.Lock()
defer freePortLock.Unlock()
for {
// Get a random free port, but do not use it yet...
var err error
freePortLock.Lock()
freePort, err = freeport.GetFreePort()
if err != nil {
freePortLock.Unlock()
continue
}

// ... First, check if the port has been used in this test run already to reduce chances of a race condition.
_, wasUsed := usedPorts.LoadOrStore(freePort, true)
freePortLock.Unlock()

// The port hasn't been used in this test run - we can use it. It was stored in usedPorts, so it will not be
// used again during this test run.
Expand Down
Loading