From 45bdea2a8c7d3e8c22a7da6b65d6d9ae9ff5f392 Mon Sep 17 00:00:00 2001 From: AlinsRan Date: Thu, 6 Aug 2026 14:29:40 +0800 Subject: [PATCH] test: fix the broken TCPRoute e2e listener port and de-flake two stream/ingress specs (backport apache/apisix-ingress-controller#2836) Signed-off-by: AlinsRan (cherry picked from commit 39325e8f4598c1d45d821fea445e9dff2828c216) --- test/e2e/gatewayapi/tcproute.go | 51 +++------------------------------ test/e2e/gatewayapi/tlsroute.go | 25 ++++++++++------ test/e2e/ingress/ingress.go | 23 +++++++++++---- 3 files changed, 37 insertions(+), 62 deletions(-) diff --git a/test/e2e/gatewayapi/tcproute.go b/test/e2e/gatewayapi/tcproute.go index 359c4c46..ad5d1c40 100644 --- a/test/e2e/gatewayapi/tcproute.go +++ b/test/e2e/gatewayapi/tcproute.go @@ -34,8 +34,9 @@ import ( var _ = Describe("TCPRoute E2E Test", Label("networking.k8s.io", "tcproute"), func() { s := scaffold.NewDefaultScaffold() - Context("TCPRoute Base", func() { - var tcpGateway = ` + + // Shared by every TCPRoute context so the listener port cannot drift between them. + var tcpGateway = ` apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: @@ -59,6 +60,7 @@ spec: name: apisix-proxy-config ` + Context("TCPRoute Base", func() { var tcpRoute = ` apiVersion: gateway.networking.k8s.io/v1 kind: TCPRoute @@ -114,27 +116,6 @@ spec: }) Context("TCPRoute With BackendTrafficPolicy", func() { - var tcpGateway = ` -apiVersion: gateway.networking.k8s.io/v1 -kind: Gateway -metadata: - name: %s -spec: - gatewayClassName: %s - listeners: - - name: tcp - protocol: TCP - port: 80 - allowedRoutes: - kinds: - - kind: TCPRoute - infrastructure: - parametersRef: - group: apisix.apache.org - kind: GatewayProxy - name: apisix-proxy-config -` - var tcpRoute = ` apiVersion: gateway.networking.k8s.io/v1 kind: TCPRoute @@ -199,30 +180,6 @@ spec: }) Context("TCPRoute With L4RoutePolicy", func() { - var tcpGateway = ` -apiVersion: gateway.networking.k8s.io/v1 -kind: Gateway -metadata: - name: %s -spec: - gatewayClassName: %s - listeners: - - name: tcp - protocol: TCP - # Must equal APISIX's physical stream_proxy TCP port so that when - # listener_port_match_mode=auto the injected server_port matches the port - # connections arrive on (see apache/apisix-ingress-controller#2818). - port: 9100 - allowedRoutes: - kinds: - - kind: TCPRoute - infrastructure: - parametersRef: - group: apisix.apache.org - kind: GatewayProxy - name: apisix-proxy-config -` - var tcpRoute = ` apiVersion: gateway.networking.k8s.io/v1 kind: TCPRoute diff --git a/test/e2e/gatewayapi/tlsroute.go b/test/e2e/gatewayapi/tlsroute.go index 08d4e4a3..fb06be9c 100644 --- a/test/e2e/gatewayapi/tlsroute.go +++ b/test/e2e/gatewayapi/tlsroute.go @@ -20,6 +20,7 @@ package gatewayapi import ( "fmt" "net/http" + "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -88,17 +89,22 @@ spec: s.ResourceApplied("TLSRoute", "tls-route", tlsRoute, 1) client := s.NewAPISIXClientWithTLSProxy(host) + // TLSRoute is served by the stream subsystem through a port-forward + // tunnel, which needs the same headroom as the other stream specs + // (tcproute/udproute); the 30s default is too tight on a loaded runner. s.RequestAssert(&scaffold.RequestAssert{ - Client: client, - Method: http.MethodGet, - Path: "/ip", - Check: scaffold.WithExpectedStatus(http.StatusOK), + Client: client, + Method: http.MethodGet, + Path: "/ip", + Check: scaffold.WithExpectedStatus(http.StatusOK), + Timeout: time.Minute * 3, }) s.RequestAssert(&scaffold.RequestAssert{ - Client: client, - Method: http.MethodGet, - Path: "/notfound", - Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Client: client, + Method: http.MethodGet, + Path: "/notfound", + Check: scaffold.WithExpectedStatus(http.StatusNotFound), + Timeout: time.Minute * 3, }) Expect(s.DeleteResourceFromString(tlsRoute)).NotTo(HaveOccurred(), "deleting TLSRoute") @@ -111,7 +117,8 @@ spec: errMsg = reporter.Err().Error() } return errMsg - }).Should(ContainSubstring("EOF"), "should get EOF after deleting TLSRoute") + }).WithTimeout(time.Minute*3). + Should(ContainSubstring("EOF"), "should get EOF after deleting TLSRoute") }) }) }) diff --git a/test/e2e/ingress/ingress.go b/test/e2e/ingress/ingress.go index f1493541..7a598f29 100644 --- a/test/e2e/ingress/ingress.go +++ b/test/e2e/ingress/ingress.go @@ -837,9 +837,14 @@ spec: }). WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) + // The preceding Not Found is also satisfied while the route is being + // rebuilt, so this must retry instead of asserting once. By("request the route with the correct vars should be OK") - s.NewAPISIXClient().GET("/get").WithHost("example.com"). - WithHeader("X-HRP-Name", "http-route-policy-0").Expect().Status(http.StatusOK) + Eventually(func() int { + return s.NewAPISIXClient().GET("/get").WithHost("example.com"). + WithHeader("X-HRP-Name", "http-route-policy-0").Expect().Raw().StatusCode + }). + WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) By("update the HTTPRoutePolicy") err = s.CreateResourceFromStringWithNamespace(httpRoutePolicySpec1, s.Namespace()) @@ -853,8 +858,11 @@ spec: WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) By("request with the new vars should be OK") - s.NewAPISIXClient().GET("/get").WithHost("example.com"). - WithQuery("hrp_name", "http-route-policy-0").Expect().Status(http.StatusOK) + Eventually(func() int { + return s.NewAPISIXClient().GET("/get").WithHost("example.com"). + WithQuery("hrp_name", "http-route-policy-0").Expect().Raw().StatusCode + }). + WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) By("update the HTTPRoutePolicy's targetRef") err = s.CreateResourceFromStringWithNamespace(httpRoutePolicySpec2, s.Namespace()) @@ -877,8 +885,11 @@ spec: WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusNotFound)) By("request the route with the correct vars should be OK") - s.NewAPISIXClient().GET("/get").WithHost("example.com"). - WithHeader("X-HRP-Name", "http-route-policy-0").Expect().Status(http.StatusOK) + Eventually(func() int { + return s.NewAPISIXClient().GET("/get").WithHost("example.com"). + WithHeader("X-HRP-Name", "http-route-policy-0").Expect().Raw().StatusCode + }). + WithTimeout(20 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK)) By("apply conflict HTTPRoutePolicy") err = s.CreateResourceFromStringWithNamespace(httpRoutePolicySpec3, s.Namespace())