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

tokers 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 cdf84ca  fix: zero weight service cannot be configured (#370)
cdf84ca is described below

commit cdf84ca1eb6ae2cff2397c0a3bfbb6d4b4884bc9
Author: Alex Zhang <[email protected]>
AuthorDate: Wed Apr 14 15:07:15 2021 +0800

    fix: zero weight service cannot be configured (#370)
---
 go.mod                                             |  8 ----
 go.sum                                             | 16 -------
 pkg/kube/apisix/apis/config/v2alpha1/types.go      |  2 +-
 .../apis/config/v2alpha1/zz_generated.deepcopy.go  |  9 +++-
 pkg/kube/translation/apisix_route.go               |  4 +-
 pkg/kube/translation/plugin.go                     |  4 +-
 pkg/kube/translation/plugin_test.go                | 20 +++++---
 samples/deploy/crd/v1beta1/ApisixRoute.yaml        |  2 +
 test/e2e/features/traffic_split.go                 | 56 ++++++++++++++++++++++
 test/e2e/plugins/redirect.go                       |  3 +-
 10 files changed, 86 insertions(+), 38 deletions(-)

diff --git a/go.mod b/go.mod
index 59dffa4..ba02cd5 100644
--- a/go.mod
+++ b/go.mod
@@ -4,30 +4,22 @@ go 1.13
 
 require (
        github.com/gin-gonic/gin v1.6.3
-       github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
        github.com/hashicorp/go-memdb v1.0.4
        github.com/hashicorp/go-multierror v1.0.0
        github.com/hashicorp/golang-lru v0.5.3 // indirect
        github.com/imdario/mergo v0.3.11 // indirect
-       github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // 
indirect
-       github.com/mattn/go-colorable v0.1.4 // indirect
        github.com/matttproud/golang_protobuf_extensions 
v1.0.2-0.20181231171920-c182affec369 // indirect
        github.com/onsi/gomega v1.8.1 // indirect
        github.com/prometheus/client_golang v1.7.1
        github.com/prometheus/client_model v0.2.0
        github.com/prometheus/procfs v0.2.0 // indirect
-       github.com/sergi/go-diff v1.1.0 // indirect
        github.com/spf13/cobra v1.1.1
        github.com/stretchr/testify v1.6.1
-       github.com/yudai/gojsondiff v1.0.0
-       github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
-       github.com/yudai/pp v2.0.1+incompatible // indirect
        go.uber.org/multierr v1.3.0
        go.uber.org/zap v1.13.0
        golang.org/x/mod v0.3.0 // indirect
        golang.org/x/net v0.0.0-20201224014010-6772e930b67b
        golang.org/x/tools v0.0.0-20200616133436-c1934b75d054 // indirect
-       gopkg.in/resty.v1 v1.12.0
        gopkg.in/yaml.v2 v2.3.0
        k8s.io/api v0.20.2
        k8s.io/apimachinery v0.20.2
diff --git a/go.sum b/go.sum
index 6b48ff8..93e363c 100644
--- a/go.sum
+++ b/go.sum
@@ -121,7 +121,6 @@ github.com/gogo/protobuf v1.1.1/go.mod 
h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a
 github.com/gogo/protobuf v1.2.1/go.mod 
h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
 github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
 github.com/gogo/protobuf v1.3.1/go.mod 
h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
-github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b 
h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod 
h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
 github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod 
h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
 github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod 
h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -225,8 +224,6 @@ github.com/jstemmer/go-junit-report 
v0.0.0-20190106144839-af01ea7f8024/go.mod h1
 github.com/jstemmer/go-junit-report v0.9.1/go.mod 
h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
 github.com/jtolds/gls v4.20.0+incompatible/go.mod 
h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
 github.com/julienschmidt/httprouter v1.2.0/go.mod 
h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
-github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 
h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM=
-github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod 
h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
 github.com/kisielk/errcheck v1.1.0/go.mod 
h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
 github.com/kisielk/errcheck v1.2.0/go.mod 
h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
 github.com/kisielk/gotool v1.0.0/go.mod 
h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
@@ -245,10 +242,7 @@ github.com/magiconair/properties v1.8.1/go.mod 
h1:PppfXfuXeibc/6YijjN8zIbojt8czP
 github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod 
h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
 github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod 
h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
 github.com/mattn/go-colorable v0.0.9/go.mod 
h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
-github.com/mattn/go-colorable v0.1.4 
h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
-github.com/mattn/go-colorable v0.1.4/go.mod 
h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
 github.com/mattn/go-isatty v0.0.3/go.mod 
h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
-github.com/mattn/go-isatty v0.0.8/go.mod 
h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
 github.com/mattn/go-isatty v0.0.12 
h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
 github.com/mattn/go-isatty v0.0.12/go.mod 
h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
 github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod 
h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
@@ -318,8 +312,6 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod 
h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
 github.com/russross/blackfriday/v2 v2.0.1/go.mod 
h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod 
h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod 
h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
-github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
-github.com/sergi/go-diff v1.1.0/go.mod 
h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
 github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod 
h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
 github.com/sirupsen/logrus v1.2.0/go.mod 
h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
 github.com/sirupsen/logrus v1.4.2/go.mod 
h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
@@ -353,12 +345,6 @@ github.com/ugorji/go v1.1.7/go.mod 
h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
 github.com/ugorji/go/codec v1.1.7 
h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
 github.com/ugorji/go/codec v1.1.7/go.mod 
h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod 
h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
-github.com/yudai/gojsondiff v1.0.0 
h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA=
-github.com/yudai/gojsondiff v1.0.0/go.mod 
h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
-github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 
h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
-github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod 
h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
-github.com/yudai/pp v2.0.1+incompatible 
h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI=
-github.com/yudai/pp v2.0.1+incompatible/go.mod 
h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
 github.com/yuin/goldmark v1.1.27/go.mod 
h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
 go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
@@ -466,7 +452,6 @@ golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod 
h1:STP8DvDyc/dI5b8T5h
 golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod 
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod 
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod 
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod 
h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod 
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod 
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod 
h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -614,7 +599,6 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod 
h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
 gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
 gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
 gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
-gopkg.in/resty.v1 v1.12.0 h1:CuXP0Pjfw9rOuY6EP+UvtNvt5DSqHpIxILZKT/quCZI=
 gopkg.in/resty.v1 v1.12.0/go.mod 
h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 
h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod 
h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
diff --git a/pkg/kube/apisix/apis/config/v2alpha1/types.go 
b/pkg/kube/apisix/apis/config/v2alpha1/types.go
index bc4232b..4797741 100644
--- a/pkg/kube/apisix/apis/config/v2alpha1/types.go
+++ b/pkg/kube/apisix/apis/config/v2alpha1/types.go
@@ -163,7 +163,7 @@ type ApisixRouteHTTPBackend struct {
        // default is endpoints.
        ResolveGranularity string `json:"resolveGranularity" 
yaml:"resolveGranularity"`
        // Weight of this backend.
-       Weight int `json:"weight" yaml:"weight"`
+       Weight *int `json:"weight" yaml:"weight"`
 }
 
 // ApisixRouteHTTPPlugin represents an APISIX plugin.
diff --git a/pkg/kube/apisix/apis/config/v2alpha1/zz_generated.deepcopy.go 
b/pkg/kube/apisix/apis/config/v2alpha1/zz_generated.deepcopy.go
index f283e94..d3e87e6 100644
--- a/pkg/kube/apisix/apis/config/v2alpha1/zz_generated.deepcopy.go
+++ b/pkg/kube/apisix/apis/config/v2alpha1/zz_generated.deepcopy.go
@@ -66,7 +66,7 @@ func (in *ApisixRouteHTTP) DeepCopyInto(out *ApisixRouteHTTP) 
{
        if in.Backend != nil {
                in, out := &in.Backend, &out.Backend
                *out = new(ApisixRouteHTTPBackend)
-               **out = **in
+               (*in).DeepCopyInto(*out)
        }
        if in.Backends != nil {
                in, out := &in.Backends, &out.Backends
@@ -75,7 +75,7 @@ func (in *ApisixRouteHTTP) DeepCopyInto(out *ApisixRouteHTTP) 
{
                        if (*in)[i] != nil {
                                in, out := &(*in)[i], &(*out)[i]
                                *out = new(ApisixRouteHTTPBackend)
-                               **out = **in
+                               (*in).DeepCopyInto(*out)
                        }
                }
        }
@@ -107,6 +107,11 @@ func (in *ApisixRouteHTTP) DeepCopy() *ApisixRouteHTTP {
 func (in *ApisixRouteHTTPBackend) DeepCopyInto(out *ApisixRouteHTTPBackend) {
        *out = *in
        out.ServicePort = in.ServicePort
+       if in.Weight != nil {
+               in, out := &in.Weight, &out.Weight
+               *out = new(int)
+               **out = **in
+       }
        return
 }
 
diff --git a/pkg/kube/translation/apisix_route.go 
b/pkg/kube/translation/apisix_route.go
index 6336455..4cfc37a 100644
--- a/pkg/kube/translation/apisix_route.go
+++ b/pkg/kube/translation/apisix_route.go
@@ -197,8 +197,8 @@ func (t *translator) TranslateRouteV2alpha1(ar 
*configv2alpha1.ApisixRoute) ([]*
 
                if len(backends) > 0 {
                        weight := _defaultWeight
-                       if backend.Weight != 0 {
-                               weight = backend.Weight
+                       if backend.Weight != nil {
+                               weight = *backend.Weight
                        }
                        ups, plugin, err := t.translateTrafficSplitPlugin(ar, 
weight, backends)
                        if err != nil {
diff --git a/pkg/kube/translation/plugin.go b/pkg/kube/translation/plugin.go
index 254d8b9..c76f600 100644
--- a/pkg/kube/translation/plugin.go
+++ b/pkg/kube/translation/plugin.go
@@ -38,8 +38,8 @@ func (t *translator) translateTrafficSplitPlugin(ar 
*configv2alpha1.ApisixRoute,
                upstreams = append(upstreams, ups)
 
                weight := _defaultWeight
-               if backend.Weight != 0 {
-                       weight = backend.Weight
+               if backend.Weight != nil {
+                       weight = *backend.Weight
                }
                wups = append(wups, 
apisixv1.TrafficSplitConfigRuleWeightedUpstream{
                        UpstreamID: ups.ID,
diff --git a/pkg/kube/translation/plugin_test.go 
b/pkg/kube/translation/plugin_test.go
index ba72272..28916fe 100644
--- a/pkg/kube/translation/plugin_test.go
+++ b/pkg/kube/translation/plugin_test.go
@@ -126,6 +126,8 @@ func TestTranslateTrafficSplitPlugin(t *testing.T) {
        <-processCh
        <-processCh
 
+       weight10 := 10
+       weight20 := 20
        backends := []*configv2alpha1.ApisixRouteHTTPBackend{
                {
                        ServiceName: "svc-1",
@@ -133,7 +135,7 @@ func TestTranslateTrafficSplitPlugin(t *testing.T) {
                                Type:   intstr.String,
                                StrVal: "port1",
                        },
-                       Weight: 10,
+                       Weight: &weight10,
                },
                {
                        ServiceName: "svc-1",
@@ -142,7 +144,7 @@ func TestTranslateTrafficSplitPlugin(t *testing.T) {
                                IntVal: 443,
                        },
                        ResolveGranularity: "service",
-                       Weight:             20,
+                       Weight:             &weight20,
                },
        }
 
@@ -293,6 +295,9 @@ func TestTranslateTrafficSplitPluginWithSameUpstreams(t 
*testing.T) {
        <-processCh
        <-processCh
 
+       weigth10 := 10
+       weight20 := 20
+
        backends := []*configv2alpha1.ApisixRouteHTTPBackend{
                {
                        ServiceName: "svc-1",
@@ -300,7 +305,7 @@ func TestTranslateTrafficSplitPluginWithSameUpstreams(t 
*testing.T) {
                                Type:   intstr.String,
                                StrVal: "port1",
                        },
-                       Weight: 10,
+                       Weight: &weigth10,
                },
                {
                        ServiceName: "svc-1",
@@ -308,7 +313,7 @@ func TestTranslateTrafficSplitPluginWithSameUpstreams(t 
*testing.T) {
                                Type:   intstr.String,
                                StrVal: "port1",
                        },
-                       Weight: 20,
+                       Weight: &weight20,
                },
        }
 
@@ -463,6 +468,9 @@ func TestTranslateTrafficSplitPluginBadCases(t *testing.T) {
        <-processCh
        <-processCh
 
+       weight10 := 10
+       weight20 := 20
+
        backends := []*configv2alpha1.ApisixRouteHTTPBackend{
                {
                        ServiceName: "svc-2",
@@ -470,7 +478,7 @@ func TestTranslateTrafficSplitPluginBadCases(t *testing.T) {
                                Type:   intstr.String,
                                StrVal: "port1",
                        },
-                       Weight: 10,
+                       Weight: &weight10,
                },
                {
                        ServiceName: "svc-1",
@@ -478,7 +486,7 @@ func TestTranslateTrafficSplitPluginBadCases(t *testing.T) {
                                Type:   intstr.String,
                                StrVal: "port1",
                        },
-                       Weight: 20,
+                       Weight: &weight20,
                },
        }
 
diff --git a/samples/deploy/crd/v1beta1/ApisixRoute.yaml 
b/samples/deploy/crd/v1beta1/ApisixRoute.yaml
index bc933d1..5ab8ccd 100644
--- a/samples/deploy/crd/v1beta1/ApisixRoute.yaml
+++ b/samples/deploy/crd/v1beta1/ApisixRoute.yaml
@@ -152,6 +152,7 @@ spec:
                         enum: ["endpoint", "service"]
                       weight:
                         type: integer
+                        minimum: 0
                     required:
                       - serviceName
                       - servicePort
@@ -173,6 +174,7 @@ spec:
                           enum: ["endpoint", "service"]
                         weight:
                           type: integer
+                          minimum: 0
                     required:
                       - serviceName
                       - servicePort
diff --git a/test/e2e/features/traffic_split.go 
b/test/e2e/features/traffic_split.go
index de7bcda..a1f98c1 100644
--- a/test/e2e/features/traffic_split.go
+++ b/test/e2e/features/traffic_split.go
@@ -90,4 +90,60 @@ spec:
                dev := math.Abs(float64(num200)/float64(num404) - float64(2))
                assert.Less(ginkgo.GinkgoT(), dev, 0.2)
        })
+
+       ginkgo.It("zero-weight", func() {
+               backendSvc, backendPorts := s.DefaultHTTPBackend()
+               adminSvc, adminPort := s.ApisixAdminServiceAndPort()
+               ar := fmt.Sprintf(`
+apiVersion: apisix.apache.org/v2alpha1
+kind: ApisixRoute
+metadata:
+ name: httpbin-route
+spec:
+ http:
+ - name: rule1
+   match:
+     hosts:
+     - httpbin.org
+     paths:
+       - /get
+   backends:
+   - serviceName: %s
+     servicePort: %d
+     weight: 100
+   - serviceName: %s
+     servicePort: %d
+     weight: 0
+`, backendSvc, backendPorts[0], adminSvc, adminPort)
+
+               assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
+
+               err := s.EnsureNumApisixUpstreamsCreated(2)
+               assert.Nil(ginkgo.GinkgoT(), err, "Checking number of 
upstreams")
+               err = s.EnsureNumApisixRoutesCreated(1)
+               assert.Nil(ginkgo.GinkgoT(), err, "Checking number of routes")
+
+               // Send requests to APISIX.
+               var (
+                       num404 int
+                       num200 int
+               )
+               for i := 0; i < 90; i++ {
+                       // For requests sent to http-admin, 404 will be given.
+                       // For requests sent to httpbin, 200 will be given.
+                       resp := 
s.NewAPISIXClient().GET("/get").WithHeader("Host", "httpbin.org").Expect()
+                       status := resp.Raw().StatusCode
+                       if status != http.StatusOK && status != 
http.StatusNotFound {
+                               assert.FailNow(ginkgo.GinkgoT(), "invalid 
status code")
+                       }
+                       if status == 200 {
+                               num200++
+                               resp.Body().Contains("origin")
+                       } else {
+                               num404++
+                       }
+               }
+               assert.Equal(ginkgo.GinkgoT(), num404, 0)
+               assert.Equal(ginkgo.GinkgoT(), num200, 90)
+       })
 })
diff --git a/test/e2e/plugins/redirect.go b/test/e2e/plugins/redirect.go
index 0cdc3b2..230fe2a 100644
--- a/test/e2e/plugins/redirect.go
+++ b/test/e2e/plugins/redirect.go
@@ -17,6 +17,7 @@ package plugins
 import (
        "fmt"
        "net/http"
+       "time"
 
        "github.com/onsi/ginkgo"
        "github.com/stretchr/testify/assert"
@@ -176,7 +177,7 @@ spec:
 `, backendSvc, backendPorts[0])
 
                assert.Nil(ginkgo.GinkgoT(), s.CreateResourceFromString(ar))
-
+               time.Sleep(5 * time.Second)
                err := s.EnsureNumApisixUpstreamsCreated(1)
                assert.Nil(ginkgo.GinkgoT(), err, "Checking number of 
upstreams")
                err = s.EnsureNumApisixRoutesCreated(1)

Reply via email to