@@ -38,6 +38,7 @@ func setup() {
38
38
util .KubeApply ("metaprotocol" , "testdata/metaprotocol-sample.yaml" , "" )
39
39
util .KubeApply ("metaprotocol" , "testdata/serviceentry.yaml" , "" )
40
40
util .KubeApply ("metaprotocol" , "testdata/destinationrule.yaml" , "" )
41
+ util .KubeApply ("metaprotocol" , "testdata/rate-limit-server/" , "" )
41
42
}
42
43
43
44
func shutdown () {
@@ -145,3 +146,54 @@ func testAttributeMatch(matchPattern string, t *testing.T) {
145
146
}
146
147
}
147
148
}
149
+
150
+ func TestLocalRateLimit (t * testing.T ) {
151
+ util .WaitForDeploymentsReady ("metaprotocol" , 10 * time .Minute , "" )
152
+ util .KubeApply ("metaprotocol" , "testdata/metarouter-local-ratelimit.yaml" , "" )
153
+ defer util .KubeDelete ("metaprotocol" , "testdata/metarouter-local-ratelimit.yaml" , "" )
154
+
155
+ log .Info ("Waiting for rules to propagate ..." )
156
+ time .Sleep (1 * time .Minute )
157
+ consumerPod , _ := util .GetPodName ("metaprotocol" , "app=dubbo-sample-consumer" , "" )
158
+ success := 0
159
+ for i := 0 ; i < 10 ; i ++ {
160
+ dubboResponse , _ := util .PodExec ("metaprotocol" , consumerPod , "dubbo-sample-consumer" ,
161
+ "curl -s 127.0.0.1:9009/hello" , false , "" )
162
+ response := "response from dubbo-sample-provider"
163
+ log .Info (dubboResponse )
164
+ if strings .Contains (dubboResponse , response ) {
165
+ success ++
166
+ }
167
+ }
168
+ if success != 2 {
169
+ t .Errorf ("local rate limit failed, want: %v got:%v " , 2 , success )
170
+ } else {
171
+ t .Logf ("%v requests have been sent to server" , success )
172
+ }
173
+ }
174
+
175
+ func TestGlobalRateLimit (t * testing.T ) {
176
+ util .WaitForDeploymentsReady ("metaprotocol" , 10 * time .Minute , "" )
177
+ util .KubeApply ("metaprotocol" , "testdata/metarouter-global-ratelimit.yaml" , "" )
178
+ defer util .KubeDelete ("metaprotocol" , "testdata/metarouter-global-ratelimit.yaml" , "" )
179
+
180
+ log .Info ("Waiting for rules to propagate ..." )
181
+ time .Sleep (1 * time .Minute )
182
+ consumerPod , _ := util .GetPodName ("metaprotocol" , "app=dubbo-sample-consumer" , "" )
183
+ success := 0
184
+ for i := 0 ; i < 20 ; i ++ {
185
+ dubboResponse , _ := util .PodExec ("metaprotocol" , consumerPod , "dubbo-sample-consumer" ,
186
+ "curl -s 127.0.0.1:9009/hello" , false , "" )
187
+ response := "response from dubbo-sample-provider"
188
+ log .Info (dubboResponse )
189
+ if strings .Contains (dubboResponse , response ) {
190
+ success ++
191
+ }
192
+ }
193
+
194
+ if success != 10 {
195
+ t .Errorf ("global rate limit failed, want: %v got:%v " , 10 , success )
196
+ } else {
197
+ t .Logf ("%v requests have been sent to server" , success )
198
+ }
199
+ }
0 commit comments