Skip to content

Commit

Permalink
Test(e2e): List entities instead of dump.Get to fetch Kong config in …
Browse files Browse the repository at this point in the history
…e2e tests (#6358)

* WIP try lock for longer in GetFreePort

* List entities instead of dump.Get for getting config from gateways

* update test logs for fetching config from gateway pod

* clear list option
  • Loading branch information
randmonkey authored Aug 1, 2024
1 parent 56aa4a1 commit cf74455
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
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

0 comments on commit cf74455

Please sign in to comment.