From 8dd261c574149b414912db2eececb123dc6b6930 Mon Sep 17 00:00:00 2001 From: Yi Tao Date: Tue, 30 Jul 2024 18:27:42 +0800 Subject: [PATCH 1/4] WIP try lock for longer in GetFreePort --- test/helpers/ports.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/helpers/ports.go b/test/helpers/ports.go index 019b3e2031..d55e106e0a 100644 --- a/test/helpers/ports.go +++ b/test/helpers/ports.go @@ -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. From 89b200df393d8f8ab094508b65e96f39737e6d77 Mon Sep 17 00:00:00 2001 From: Yi Tao Date: Wed, 31 Jul 2024 11:08:37 +0800 Subject: [PATCH 2/4] List entities instead of dump.Get for getting config from gateways --- test/e2e/all_in_one_test.go | 1 - test/e2e/helpers_test.go | 40 +++++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/test/e2e/all_in_one_test.go b/test/e2e/all_in_one_test.go index fc7e4b197b..be2268a8d6 100644 --- a/test/e2e/all_in_one_test.go +++ b/test/e2e/all_in_one_test.go @@ -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() } diff --git a/test/e2e/helpers_test.go b/test/e2e/helpers_test.go index b5b0e7678b..b685790d02 100644 --- a/test/e2e/helpers_test.go +++ b/test/e2e/helpers_test.go @@ -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" @@ -528,31 +527,46 @@ func verifyIngressWithEchoBackendsInAdminAPI( t.Helper() require.Eventually(t, func() bool { - d, err := dump.Get(ctx, kongClient, dump.Config{}) + start := time.Now() + defer t.Logf("Try fetching 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 { + if len(services) != 1 || services[0].ID == nil { t.Log("still no service found...") return false } - if len(d.Routes) != 1 { + + routes, _, err := kongClient.Routes.ListForService(ctx, services[0].ID, &kong.ListOpt{Size: 10}) + if err != nil { + t.Logf("failed to list routes for service %s: %v", *services[0].ID, err) + return false + } + if len(routes) != 1 { t.Log("still no route found...") 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...") + + 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("still no upstreams found...") return false } - if len(d.Targets) != noReplicas { - t.Log("still no target found...") + + 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.Log("still no targets found...") return false } return true From 481ae58cf8766d7f3a8bd99fd68bb0e67727e141 Mon Sep 17 00:00:00 2001 From: Yi Tao Date: Thu, 1 Aug 2024 10:42:50 +0800 Subject: [PATCH 3/4] update test logs for fetching config from gateway pod --- test/e2e/helpers_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/e2e/helpers_test.go b/test/e2e/helpers_test.go index b685790d02..a89ad7b194 100644 --- a/test/e2e/helpers_test.go +++ b/test/e2e/helpers_test.go @@ -528,7 +528,9 @@ func verifyIngressWithEchoBackendsInAdminAPI( require.Eventually(t, func() bool { start := time.Now() - defer t.Logf("Try fetching config from %q started at %s, duration %v", kongClient.BaseRootURL(), start.Format(time.RFC3339), time.Since(start)) + 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 { @@ -536,7 +538,7 @@ func verifyIngressWithEchoBackendsInAdminAPI( return false } if len(services) != 1 || services[0].ID == nil { - t.Log("still no service found...") + t.Logf("%d services found, expected 1", len(services)) return false } @@ -546,7 +548,7 @@ func verifyIngressWithEchoBackendsInAdminAPI( return false } if len(routes) != 1 { - t.Log("still no route found...") + t.Logf("%d routes found under service %s, expected 1", len(routes), *services[0].ID) return false } @@ -556,7 +558,7 @@ func verifyIngressWithEchoBackendsInAdminAPI( return false } if len(upstreams) != 1 || upstreams[0].ID == nil { - t.Logf("still no upstreams found...") + t.Logf("%d upstreams found, expected 1", len(upstreams)) return false } @@ -566,7 +568,7 @@ func verifyIngressWithEchoBackendsInAdminAPI( return false } if len(targets) != noReplicas { - t.Log("still no targets found...") + t.Logf("%d targets found, expected %d", len(targets), noReplicas) return false } return true From 00eabb2f08d71a26c0c0f313714ea9d3204d15bf Mon Sep 17 00:00:00 2001 From: Yi Tao Date: Thu, 1 Aug 2024 13:55:04 +0800 Subject: [PATCH 4/4] clear list option --- test/e2e/helpers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/helpers_test.go b/test/e2e/helpers_test.go index a89ad7b194..a0a8649521 100644 --- a/test/e2e/helpers_test.go +++ b/test/e2e/helpers_test.go @@ -542,7 +542,7 @@ func verifyIngressWithEchoBackendsInAdminAPI( return false } - routes, _, err := kongClient.Routes.ListForService(ctx, services[0].ID, &kong.ListOpt{Size: 10}) + 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