This is an automated email from the ASF dual-hosted git repository.

alinsran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git


The following commit(s) were added to refs/heads/master by this push:
     new b70e22eb fix: wss related tests are unstable (#2675)
b70e22eb is described below

commit b70e22ebac75a4e790d770cd49fbfba9730c1664
Author: AlinsRan <[email protected]>
AuthorDate: Wed Dec 10 10:32:42 2025 +0800

    fix: wss related tests are unstable (#2675)
---
 internal/controller/gateway_controller.go |  4 ++++
 internal/controller/indexer/ssl_host.go   |  6 ++++--
 test/e2e/crds/v2/route.go                 | 21 +++++-------------
 test/e2e/framework/manifests/apisix.yaml  |  3 +++
 test/e2e/framework/manifests/nginx.yaml   | 10 +++++++--
 test/e2e/gatewayapi/httproute.go          | 26 +++++-----------------
 test/e2e/ingress/ingress.go               | 36 ++++++++++---------------------
 test/e2e/scaffold/apisix_deployer.go      | 13 +++++++++++
 test/e2e/scaffold/scaffold.go             | 35 ++++++++++++++++++++++++++++++
 9 files changed, 88 insertions(+), 66 deletions(-)

diff --git a/internal/controller/gateway_controller.go 
b/internal/controller/gateway_controller.go
index db416817..147bdd17 100644
--- a/internal/controller/gateway_controller.go
+++ b/internal/controller/gateway_controller.go
@@ -140,6 +140,10 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, 
req ctrl.Request) (ct
                }
                return ctrl.Result{}, err
        }
+       if !r.checkGatewayClass(gateway) {
+               return ctrl.Result{}, nil
+       }
+
        conditionProgrammedStatus, conditionProgrammedMsg := true, "Programmed"
 
        r.Log.Info("gateway has been accepted", "gateway", gateway.GetName())
diff --git a/internal/controller/indexer/ssl_host.go 
b/internal/controller/indexer/ssl_host.go
index 9838d43f..6762aa30 100644
--- a/internal/controller/indexer/ssl_host.go
+++ b/internal/controller/indexer/ssl_host.go
@@ -69,9 +69,11 @@ func GatewayTLSHostIndexFunc(rawObj client.Object) []string {
                }
        }
 
-       tlsHostIndexLogger.Info("GatewayTLSHostIndexFunc", "hosts", 
hostSetToSlice(hosts), "len", len(hostSetToSlice(hosts)))
+       hostsSlice := hostSetToSlice(hosts)
 
-       return hostSetToSlice(hosts)
+       tlsHostIndexLogger.V(1).Info("GatewayTLSHostIndexFunc", "hosts", 
hostsSlice)
+
+       return hostsSlice
 }
 
 // IngressTLSHostIndexFunc indexes Ingresses by their TLS SNI hosts.
diff --git a/test/e2e/crds/v2/route.go b/test/e2e/crds/v2/route.go
index f7b0f587..67c6770f 100644
--- a/test/e2e/crds/v2/route.go
+++ b/test/e2e/crds/v2/route.go
@@ -2145,22 +2145,11 @@ spec:
                        time.Sleep(6 * time.Second)
 
                        By("verify wss connection")
-                       u := url.URL{
-                               Scheme: "wss",
-                               Host:   s.GetAPISIXHTTPSEndpoint(),
-                               Path:   "/ws",
-                       }
-                       headers := http.Header{"Host": []string{"api6.com"}}
-                       dialer := websocket.Dialer{
-                               TLSClientConfig: &tls.Config{
-                                       InsecureSkipVerify: true,
-                                       ServerName:         "api6.com",
-                               },
-                       }
-
-                       conn, resp, err := dialer.Dial(u.String(), headers)
-                       Expect(err).ShouldNot(HaveOccurred(), "WebSocket 
handshake")
-                       
Expect(resp.StatusCode).Should(Equal(http.StatusSwitchingProtocols))
+                       hostname := "api6.com"
+                       conn := s.NewWebsocketClient(&tls.Config{
+                               InsecureSkipVerify: true,
+                               ServerName:         hostname,
+                       }, "/ws", http.Header{"Host": []string{hostname}})
 
                        defer func() {
                                _ = conn.Close()
diff --git a/test/e2e/framework/manifests/apisix.yaml 
b/test/e2e/framework/manifests/apisix.yaml
index eada5041..310398e1 100644
--- a/test/e2e/framework/manifests/apisix.yaml
+++ b/test/e2e/framework/manifests/apisix.yaml
@@ -66,15 +66,18 @@ metadata:
   name: apisix
   labels:
     app.kubernetes.io/name: apisix
+    app: apisix
 spec:
   replicas: {{ default 1 .Replicas }}
   selector:
     matchLabels:
       app.kubernetes.io/name: apisix
+      app: apisix
   template:
     metadata:
       labels:
         app.kubernetes.io/name: apisix
+        app: apisix
     spec:
       initContainers:
         - name: config-setup
diff --git a/test/e2e/framework/manifests/nginx.yaml 
b/test/e2e/framework/manifests/nginx.yaml
index abdc7e9e..0c54585a 100644
--- a/test/e2e/framework/manifests/nginx.yaml
+++ b/test/e2e/framework/manifests/nginx.yaml
@@ -124,13 +124,19 @@ spec:
       containers:
         - livenessProbe:
             failureThreshold: 3
-            initialDelaySeconds: 1
-            periodSeconds: 5
+            initialDelaySeconds: 10
+            periodSeconds: 15
             successThreshold: 1
             httpGet:
               path: /healthz
               port: 80
             timeoutSeconds: 2
+          readinessProbe:
+            httpGet:
+              path: /healthz
+              port: 80
+            initialDelaySeconds: 5
+            periodSeconds: 5
           image: "openresty/openresty:1.27.1.2-4-bullseye-fat"
           imagePullPolicy: IfNotPresent
           name: nginx
diff --git a/test/e2e/gatewayapi/httproute.go b/test/e2e/gatewayapi/httproute.go
index d36daeb4..a00d1693 100644
--- a/test/e2e/gatewayapi/httproute.go
+++ b/test/e2e/gatewayapi/httproute.go
@@ -22,7 +22,6 @@ import (
        "crypto/tls"
        "fmt"
        "net/http"
-       "net/url"
        "strings"
        "time"
 
@@ -2504,28 +2503,13 @@ spec:
 
                It("WSS backend", func() {
                        s.ResourceApplied("HTTPRoute", "nginx-wss", 
fmt.Sprintf(httprouteWithWSS, s.Namespace()), 1)
-                       time.Sleep(6 * time.Second)
 
                        By("verify wss connection")
-                       u := url.URL{
-                               Scheme: "wss",
-                               Host:   s.GetAPISIXHTTPSEndpoint(),
-                               Path:   "/ws",
-                       }
-                       headers := http.Header{"Host": []string{"api6.com"}}
-
                        hostname := "api6.com"
-
-                       dialer := websocket.Dialer{
-                               TLSClientConfig: &tls.Config{
-                                       InsecureSkipVerify: true,
-                                       ServerName:         hostname,
-                               },
-                       }
-
-                       conn, resp, err := dialer.Dial(u.String(), headers)
-                       Expect(err).ShouldNot(HaveOccurred(), "WebSocket 
handshake")
-                       
Expect(resp.StatusCode).Should(Equal(http.StatusSwitchingProtocols))
+                       conn := s.NewWebsocketClient(&tls.Config{
+                               InsecureSkipVerify: true,
+                               ServerName:         hostname,
+                       }, "/ws", http.Header{"Host": []string{hostname}})
 
                        defer func() {
                                _ = conn.Close()
@@ -2533,7 +2517,7 @@ spec:
 
                        By("send and receive message through WebSocket")
                        testMessage := "hello, this is APISIX"
-                       err = conn.WriteMessage(websocket.TextMessage, 
[]byte(testMessage))
+                       err := conn.WriteMessage(websocket.TextMessage, 
[]byte(testMessage))
                        Expect(err).ShouldNot(HaveOccurred(), "writing 
WebSocket message")
 
                        // Then our echo
diff --git a/test/e2e/ingress/ingress.go b/test/e2e/ingress/ingress.go
index 12db5191..6329b681 100644
--- a/test/e2e/ingress/ingress.go
+++ b/test/e2e/ingress/ingress.go
@@ -23,7 +23,6 @@ import (
        "encoding/base64"
        "fmt"
        "net/http"
-       "net/url"
        "strings"
        "time"
 
@@ -944,14 +943,13 @@ spec:
                        By("create Ingress")
                        err := 
s.CreateResourceFromStringWithNamespace(fmt.Sprintf(ingress, s.Namespace()), 
s.Namespace())
                        Expect(err).NotTo(HaveOccurred(), "creating Ingress")
-                       time.Sleep(5 * time.Second)
 
                        By("verify Ingress works")
-                       s.NewAPISIXClient().
-                               GET("/get").
-                               WithHost("ingress.example.com").
-                               Expect().
-                               Status(200)
+                       s.RequestAssert(&scaffold.RequestAssert{
+                               Method: "GET",
+                               Host:   "ingress.example.com",
+                               Check:  
scaffold.WithExpectedStatus(http.StatusOK),
+                       })
 
                        By("create additional gateway group to get new admin 
key")
                        additionalGatewayGroupID, _, err = 
s.Deployer.CreateAdditionalGateway("gateway-proxy-update")
@@ -1070,25 +1068,13 @@ spec:
                        createSecret(s, _secretName)
                        By("create Ingress")
                        
Expect(s.CreateResourceFromString(fmt.Sprintf(ingressWithWSS, 
s.Namespace()))).ShouldNot(HaveOccurred(), "creating Ingress")
-                       time.Sleep(6 * time.Second)
 
                        By("verify wss connection")
-                       u := url.URL{
-                               Scheme: "wss",
-                               Host:   s.GetAPISIXHTTPSEndpoint(),
-                               Path:   "/ws",
-                       }
-                       headers := http.Header{"Host": []string{"api6.com"}}
-                       dialer := websocket.Dialer{
-                               TLSClientConfig: &tls.Config{
-                                       InsecureSkipVerify: true,
-                                       ServerName:         "api6.com",
-                               },
-                       }
-
-                       conn, resp, err := dialer.Dial(u.String(), headers)
-                       Expect(err).ShouldNot(HaveOccurred(), "WebSocket 
handshake")
-                       
Expect(resp.StatusCode).Should(Equal(http.StatusSwitchingProtocols))
+                       hostname := "api6.com"
+                       conn := s.NewWebsocketClient(&tls.Config{
+                               InsecureSkipVerify: true,
+                               ServerName:         hostname,
+                       }, "/ws", http.Header{"Host": []string{hostname}})
 
                        defer func() {
                                _ = conn.Close()
@@ -1096,7 +1082,7 @@ spec:
 
                        By("send and receive message through WebSocket")
                        testMessage := "hello, this is APISIX"
-                       err = conn.WriteMessage(websocket.TextMessage, 
[]byte(testMessage))
+                       err := conn.WriteMessage(websocket.TextMessage, 
[]byte(testMessage))
                        Expect(err).ShouldNot(HaveOccurred(), "writing 
WebSocket message")
 
                        // Then our echo
diff --git a/test/e2e/scaffold/apisix_deployer.go 
b/test/e2e/scaffold/apisix_deployer.go
index 58f6a79c..5786710b 100644
--- a/test/e2e/scaffold/apisix_deployer.go
+++ b/test/e2e/scaffold/apisix_deployer.go
@@ -111,6 +111,19 @@ func (s *APISIXDeployer) AfterEach() {
                if output != "" {
                        _, _ = fmt.Fprintln(GinkgoWriter, output)
                }
+
+               _, _ = fmt.Fprintln(GinkgoWriter, "Dumping APISIX logs:")
+               output = s.GetDeploymentLogs("apisix")
+               if output != "" {
+                       _, _ = fmt.Fprintln(GinkgoWriter, output)
+               }
+               if framework.ProviderType == 
framework.ProviderTypeAPISIXStandalone && s.adminTunnel != nil {
+                       client := NewClient("http", s.adminTunnel.Endpoint())
+                       reporter := &ErrorReporter{}
+                       body := 
client.GET("/apisix/admin/configs").WithHeader("X-API-KEY", 
s.AdminKey()).WithReporter(reporter).Expect().Body().Raw()
+                       _, _ = fmt.Fprintln(GinkgoWriter, "Dumping APISIX 
configs:")
+                       _, _ = fmt.Fprintln(GinkgoWriter, body)
+               }
        }
 
        // Delete all additional gateways
diff --git a/test/e2e/scaffold/scaffold.go b/test/e2e/scaffold/scaffold.go
index 799cc798..af6d8289 100644
--- a/test/e2e/scaffold/scaffold.go
+++ b/test/e2e/scaffold/scaffold.go
@@ -30,6 +30,7 @@ import (
 
        "github.com/api7/gopkg/pkg/log"
        "github.com/gavv/httpexpect/v2"
+       "github.com/gorilla/websocket"
        "github.com/gruntwork-io/terratest/modules/k8s"
        "github.com/gruntwork-io/terratest/modules/testing"
        . "github.com/onsi/ginkgo/v2" //nolint:staticcheck
@@ -562,6 +563,40 @@ func (s *Scaffold) GetMetricsEndpoint() string {
        return fmt.Sprintf("http://%s/metrics";, tunnel.Endpoint())
 }
 
+func (s *Scaffold) NewWebsocketClient(tls *tls.Config, path string, headers 
http.Header) *websocket.Conn {
+       var host = s.ApisixHTTPEndpoint()
+       var scheme = "ws"
+       if tls != nil {
+               scheme = "wss"
+               host = s.GetAPISIXHTTPSEndpoint()
+       }
+
+       dialer := websocket.Dialer{
+               TLSClientConfig: tls,
+       }
+
+       u := url.URL{
+               Scheme: scheme,
+               Host:   host,
+               Path:   path,
+       }
+       var conn *websocket.Conn
+
+       s.RetryAssertion(func() error {
+               c, resp, err := dialer.Dial(u.String(), headers)
+               if err != nil {
+                       return err
+               }
+               if resp == nil || resp.StatusCode != 
http.StatusSwitchingProtocols {
+                       _ = c.Close()
+                       return fmt.Errorf("unexpected status code: %d", 
resp.StatusCode)
+               }
+               conn = c
+               return nil
+       }).ShouldNot(HaveOccurred(), "establishing websocket connection")
+       return conn
+}
+
 func (s *Scaffold) ControlAPIClient() (ControlAPIClient, error) {
        tunnel := k8s.NewTunnel(s.kubectlOptions, k8s.ResourceTypeService, 
"apisix-control-api", 9090, 9090)
        if err := tunnel.ForwardPortE(s.t); err != nil {

Reply via email to