@@ -22,11 +22,13 @@ import (
2222 "fmt"
2323 "strings"
2424
25+ delaypb "github.com/Anddd7/pb/grpcbin"
2526 pb "github.com/moul/pb/grpcbin/go-grpc"
2627 "github.com/onsi/ginkgo/v2"
2728 "github.com/stretchr/testify/assert"
2829 "google.golang.org/grpc"
2930 "google.golang.org/grpc/credentials"
31+ "google.golang.org/grpc/credentials/insecure"
3032 "google.golang.org/grpc/metadata"
3133 corev1 "k8s.io/api/core/v1"
3234 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -261,47 +263,86 @@ var _ = framework.DescribeAnnotation("backend-protocol - GRPC", func() {
261263 assert .Equal (ginkgo .GinkgoT (), metadata ["content-type" ].Values [0 ], "application/grpc" )
262264 })
263265
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 "
268270
269271 annotations := make (map [string ]string )
270272 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 )
274278
275- ing := framework .NewSingleIngress (host , "/" , host , f .Namespace , framework .EchoService , 80 , annotations )
276279 f .EnsureIngress (ing )
277280
278281 f .WaitForNginxServer (host ,
279282 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 ))
283286 })
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 )
284306 })
285307
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 "
290312
291313 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 )
296320
297- ing := framework .NewSingleIngress (host , "/" , host , f .Namespace , framework .EchoService , 80 , annotations )
298321 f .EnsureIngress (ing )
299322
300323 f .WaitForNginxServer (host ,
301324 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 ))
305328 })
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 )
306347 })
307348})
0 commit comments