Skip to content

Commit 251ec49

Browse files
committed
fix: r
Signed-off-by: Ashing Zheng <[email protected]>
1 parent 36029b1 commit 251ec49

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/go-logr/zapr v1.3.0
1313
github.com/google/go-cmp v0.6.0
1414
github.com/google/uuid v1.6.0
15+
github.com/gorilla/websocket v1.5.1
1516
github.com/gruntwork-io/terratest v0.47.0
1617
github.com/hashicorp/go-memdb v1.3.4
1718
github.com/hashicorp/go-multierror v1.1.1
@@ -106,7 +107,6 @@ require (
106107
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
107108
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
108109
github.com/gorilla/mux v1.8.0 // indirect
109-
github.com/gorilla/websocket v1.5.1 // indirect
110110
github.com/gosuri/uitable v0.0.4 // indirect
111111
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
112112
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect

test/e2e/crds/v2/route.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"net"
2626
"net/http"
2727
"net/url"
28+
"strings"
2829
"time"
2930

3031
"github.com/gorilla/websocket"
@@ -755,6 +756,12 @@ spec:
755756
})
756757

757758
Context("Test ApisixRoute Traffic Split", func() {
759+
BeforeEach(func() {
760+
s.DeployNginx(framework.NginxOptions{
761+
Namespace: s.Namespace(),
762+
})
763+
})
764+
758765
It("2:1 traffic split test", func() {
759766
const apisixRouteSpec = `
760767
apiVersion: apisix.apache.org/v2
@@ -774,20 +781,16 @@ spec:
774781
- serviceName: httpbin-service-e2e-test
775782
servicePort: 80
776783
weight: 10
777-
- serviceName: %s
778-
servicePort: 9180
784+
- serviceName: nginx
785+
servicePort: 80
779786
weight: 5
780787
`
781788
By("apply ApisixRoute with traffic split")
782-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute),
783-
fmt.Sprintf(apisixRouteSpec, s.Deployer.GetAdminServiceName()))
784-
verifyRequest := func() int {
785-
return s.NewAPISIXClient().GET("/get").WithHost("httpbin.org").Expect().Raw().StatusCode
786-
}
789+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), apisixRouteSpec)
787790
By("send requests to verify traffic split")
788791
var (
789-
successCount int
790-
failCount int
792+
hitHttpbinCnt = 0
793+
hitNginxCnt = 0
791794
)
792795

793796
s.RequestAssert(&scaffold.RequestAssert{
@@ -798,16 +801,18 @@ spec:
798801
Timeout: 10 * time.Second,
799802
})
800803
for range 90 {
801-
code := verifyRequest()
802-
if code == http.StatusOK {
803-
successCount++
804+
resp := s.NewAPISIXClient().GET("/get").WithHost("httpbin.org").Expect()
805+
body := resp.Body().Raw()
806+
807+
if strings.Contains(body, "Hello") {
808+
hitNginxCnt++
804809
} else {
805-
failCount++
810+
hitHttpbinCnt++
806811
}
807812
}
808813

809814
By("verify traffic distribution ratio")
810-
ratio := float64(successCount) / float64(failCount)
815+
ratio := float64(hitHttpbinCnt) / float64(hitNginxCnt)
811816
expectedRatio := 10.0 / 5.0 // 2:1 ratio
812817
deviation := math.Abs(ratio - expectedRatio)
813818
Expect(deviation).Should(BeNumerically("<", 0.5),
@@ -838,8 +843,7 @@ spec:
838843
weight: 0
839844
`
840845
By("apply ApisixRoute with zero-weight backend")
841-
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute),
842-
fmt.Sprintf(apisixRouteSpec, s.Deployer.GetAdminServiceName()))
846+
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, new(apiv2.ApisixRoute), apisixRouteSpec)
843847
verifyRequest := func() int {
844848
return s.NewAPISIXClient().GET("/get").WithHost("httpbin.org").Expect().Raw().StatusCode
845849
}

test/e2e/scaffold/apisix_deployer.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,6 @@ func (s *APISIXDeployer) GetAdminEndpoint(svc ...*corev1.Service) string {
420420
return fmt.Sprintf("http://%s.%s:9180", svc[0].Name, svc[0].Namespace)
421421
}
422422

423-
func (s *APISIXDeployer) GetAdminServiceName() string {
424-
return s.dataplaneService.Name
425-
}
426423
func (s *APISIXDeployer) DefaultDataplaneResource() DataplaneResource {
427424
return newADCDataplaneResource(
428425
framework.ProviderType,

test/e2e/scaffold/deployer.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ type Deployer interface {
3232
CreateAdditionalGateway(namePrefix string) (string, *corev1.Service, error)
3333
CleanupAdditionalGateway(identifier string) error
3434
GetAdminEndpoint(...*corev1.Service) string
35-
GetAdminServiceName() string
3635
DefaultDataplaneResource() DataplaneResource
3736
Name() string
3837
}

0 commit comments

Comments
 (0)