@@ -22,11 +22,13 @@ import (
22
22
"fmt"
23
23
"strings"
24
24
25
+ delaypb "github.com/Anddd7/pb/grpcbin"
25
26
pb "github.com/moul/pb/grpcbin/go-grpc"
26
27
"github.com/onsi/ginkgo/v2"
27
28
"github.com/stretchr/testify/assert"
28
29
"google.golang.org/grpc"
29
30
"google.golang.org/grpc/credentials"
31
+ "google.golang.org/grpc/credentials/insecure"
30
32
"google.golang.org/grpc/metadata"
31
33
corev1 "k8s.io/api/core/v1"
32
34
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -261,47 +263,86 @@ var _ = framework.DescribeAnnotation("backend-protocol - GRPC", func() {
261
263
assert .Equal (ginkgo .GinkgoT (), metadata ["content-type" ].Values [0 ], "application/grpc" )
262
264
})
263
265
264
- ginkgo .It ("should set valid grpc timeouts for grpc " , func () {
265
- proxyConnectTimeout := "5"
266
- proxySendTimeout := "30"
267
- proxyReadtimeout := "30 "
266
+ ginkgo .It ("should return OK when request not exceed timeout " , func () {
267
+ f . NewGRPCBinDelayDeployment ()
268
+
269
+ proxyTimeout := "10 "
268
270
269
271
annotations := make (map [string ]string )
270
272
annotations ["nginx.ingress.kubernetes.io/backend-protocol" ] = "GRPC"
271
- annotations ["nginx.ingress.kubernetes.io/proxy-connect-timeout" ] = proxyConnectTimeout
272
- annotations ["nginx.ingress.kubernetes.io/proxy-send-timeout" ] = proxySendTimeout
273
- annotations ["nginx.ingress.kubernetes.io/proxy-read-timeout" ] = proxyReadtimeout
273
+ annotations ["nginx.ingress.kubernetes.io/proxy-connect-timeout" ] = proxyTimeout
274
+ annotations ["nginx.ingress.kubernetes.io/proxy-send-timeout" ] = proxyTimeout
275
+ annotations ["nginx.ingress.kubernetes.io/proxy-read-timeout" ] = proxyTimeout
276
+
277
+ ing := framework .NewSingleIngress (host , "/" , host , f .Namespace , "grpcbin-delay" , 50051 , annotations )
274
278
275
- ing := framework .NewSingleIngress (host , "/" , host , f .Namespace , framework .EchoService , 80 , annotations )
276
279
f .EnsureIngress (ing )
277
280
278
281
f .WaitForNginxServer (host ,
279
282
func (server string ) bool {
280
- return strings .Contains (server , fmt .Sprintf ("grpc_connect_timeout %ss;" , proxyConnectTimeout )) &&
281
- strings .Contains (server , fmt .Sprintf ("grpc_send_timeout %ss;" , proxySendTimeout )) &&
282
- strings .Contains (server , fmt .Sprintf ("grpc_read_timeout %ss;" , proxyReadtimeout ))
283
+ return strings .Contains (server , fmt .Sprintf ("grpc_connect_timeout %ss;" , proxyTimeout )) &&
284
+ strings .Contains (server , fmt .Sprintf ("grpc_send_timeout %ss;" , proxyTimeout )) &&
285
+ strings .Contains (server , fmt .Sprintf ("grpc_read_timeout %ss;" , proxyTimeout ))
283
286
})
287
+
288
+ conn , err := grpc .Dial (
289
+ f .GetNginxIP ()+ ":80" ,
290
+ grpc .WithTransportCredentials (insecure .NewCredentials ()),
291
+ grpc .WithAuthority (host ),
292
+ )
293
+ assert .Nil (ginkgo .GinkgoT (), err , "error creating a connection" )
294
+ defer conn .Close ()
295
+
296
+ client := delaypb .NewGrpcbinServiceClient (conn )
297
+
298
+ res , err := client .Unary (context .Background (), & delaypb.UnaryRequest {
299
+ Data : "hello" ,
300
+ })
301
+ assert .Nil (ginkgo .GinkgoT (), err )
302
+
303
+ metadata := res .GetResponseAttributes ().RequestHeaders
304
+ assert .Equal (ginkgo .GinkgoT (), metadata ["content-type" ], "application/grpc" )
305
+ assert .Equal (ginkgo .GinkgoT (), metadata [":authority" ], host )
284
306
})
285
307
286
- ginkgo .It ("should set valid grpc timeouts for grpcs " , func () {
287
- proxyConnectTimeout := "5"
288
- proxySendTimeout := "30"
289
- proxyReadtimeout := "30 "
308
+ ginkgo .It ("should return Error when request exceed timeout " , func () {
309
+ f . NewGRPCBinDelayDeployment ()
310
+
311
+ proxyTimeout := "10 "
290
312
291
313
annotations := make (map [string ]string )
292
- annotations ["nginx.ingress.kubernetes.io/backend-protocol" ] = "GRPCS"
293
- annotations ["nginx.ingress.kubernetes.io/proxy-connect-timeout" ] = proxyConnectTimeout
294
- annotations ["nginx.ingress.kubernetes.io/proxy-send-timeout" ] = proxySendTimeout
295
- annotations ["nginx.ingress.kubernetes.io/proxy-read-timeout" ] = proxyReadtimeout
314
+ annotations ["nginx.ingress.kubernetes.io/backend-protocol" ] = "GRPC"
315
+ annotations ["nginx.ingress.kubernetes.io/proxy-connect-timeout" ] = proxyTimeout
316
+ annotations ["nginx.ingress.kubernetes.io/proxy-send-timeout" ] = proxyTimeout
317
+ annotations ["nginx.ingress.kubernetes.io/proxy-read-timeout" ] = proxyTimeout
318
+
319
+ ing := framework .NewSingleIngress (host , "/" , host , f .Namespace , "grpcbin-delay" , 50051 , annotations )
296
320
297
- ing := framework .NewSingleIngress (host , "/" , host , f .Namespace , framework .EchoService , 80 , annotations )
298
321
f .EnsureIngress (ing )
299
322
300
323
f .WaitForNginxServer (host ,
301
324
func (server string ) bool {
302
- return strings .Contains (server , fmt .Sprintf ("grpc_connect_timeout %ss;" , proxyConnectTimeout )) &&
303
- strings .Contains (server , fmt .Sprintf ("grpc_send_timeout %ss;" , proxySendTimeout )) &&
304
- strings .Contains (server , fmt .Sprintf ("grpc_read_timeout %ss;" , proxyReadtimeout ))
325
+ return strings .Contains (server , fmt .Sprintf ("grpc_connect_timeout %ss;" , proxyTimeout )) &&
326
+ strings .Contains (server , fmt .Sprintf ("grpc_send_timeout %ss;" , proxyTimeout )) &&
327
+ strings .Contains (server , fmt .Sprintf ("grpc_read_timeout %ss;" , proxyTimeout ))
305
328
})
329
+
330
+ conn , err := grpc .Dial (
331
+ f .GetNginxIP ()+ ":80" ,
332
+ grpc .WithTransportCredentials (insecure .NewCredentials ()),
333
+ grpc .WithAuthority (host ),
334
+ )
335
+ assert .Nil (ginkgo .GinkgoT (), err , "error creating a connection" )
336
+ defer conn .Close ()
337
+
338
+ client := delaypb .NewGrpcbinServiceClient (conn )
339
+
340
+ _ , err = client .Unary (context .Background (), & delaypb.UnaryRequest {
341
+ Data : "hello" ,
342
+ RequestAttributes : & delaypb.RequestAttributes {
343
+ Delay : 15 ,
344
+ },
345
+ })
346
+ assert .Error (ginkgo .GinkgoT (), err )
306
347
})
307
348
})
0 commit comments