@@ -30,7 +30,6 @@ import (
3030 "google.golang.org/grpc/codes"
3131 "google.golang.org/grpc/connectivity"
3232 "google.golang.org/grpc/credentials/insecure"
33- "google.golang.org/grpc/internal"
3433 "google.golang.org/grpc/internal/grpcsync"
3534 "google.golang.org/grpc/internal/testutils"
3635 "google.golang.org/grpc/internal/testutils/xds/e2e"
@@ -224,204 +223,6 @@ func (s) TestRDSNack(t *testing.T) {
224223 waitForFailedRPCWithStatus (ctx , t , cc , status .New (codes .Unavailable , "error from xDS configuration for matched route configuration" ))
225224}
226225
227- // TestResourceNotFoundRDS tests the case where an LDS points to an RDS which
228- // returns resource not found. Before getting the resource not found, the xDS
229- // Server has not received all configuration needed, so it should Accept and
230- // Close any new connections. After it has received the resource not found
231- // error, the server should move to serving, successfully Accept Connections,
232- // and fail at the L7 level with resource not found specified.
233- func (s ) TestResourceNotFoundRDS (t * testing.T ) {
234- managementServer , nodeID , bootstrapContents , _ , cleanup := e2e .SetupManagementServer (t , e2e.ManagementServerOptions {})
235- defer cleanup ()
236- lis , err := testutils .LocalTCPListener ()
237- if err != nil {
238- t .Fatalf ("testutils.LocalTCPListener() failed: %v" , err )
239- }
240- // Setup the management server to respond with a listener resource that
241- // specifies a route name to watch, and no RDS resource corresponding to
242- // this route name.
243- host , port , err := hostPortFromListener (lis )
244- if err != nil {
245- t .Fatalf ("failed to retrieve host and port of server: %v" , err )
246- }
247-
248- listener := e2e .DefaultServerListenerWithRouteConfigName (host , port , e2e .SecurityLevelNone , "routeName" )
249- resources := e2e.UpdateOptions {
250- NodeID : nodeID ,
251- Listeners : []* v3listenerpb.Listener {listener },
252- SkipValidation : true ,
253- }
254-
255- ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
256- defer cancel ()
257- if err := managementServer .Update (ctx , resources ); err != nil {
258- t .Fatal (err )
259- }
260- serving := grpcsync .NewEvent ()
261- modeChangeOpt := xds .ServingModeCallback (func (addr net.Addr , args xds.ServingModeChangeArgs ) {
262- t .Logf ("serving mode for listener %q changed to %q, err: %v" , addr .String (), args .Mode , args .Err )
263- if args .Mode == connectivity .ServingModeServing {
264- serving .Fire ()
265- }
266- })
267-
268- server , err := xds .NewGRPCServer (grpc .Creds (insecure .NewCredentials ()), modeChangeOpt , xds .BootstrapContentsForTesting (bootstrapContents ))
269- if err != nil {
270- t .Fatalf ("Failed to create an xDS enabled gRPC server: %v" , err )
271- }
272- defer server .Stop ()
273- testgrpc .RegisterTestServiceServer (server , & testService {})
274- go func () {
275- if err := server .Serve (lis ); err != nil {
276- t .Errorf ("Serve() failed: %v" , err )
277- }
278- }()
279-
280- cc , err := grpc .NewClient (lis .Addr ().String (), grpc .WithTransportCredentials (insecure .NewCredentials ()))
281- if err != nil {
282- t .Fatalf ("failed to dial local test server: %v" , err )
283- }
284- defer cc .Close ()
285-
286- waitForFailedRPCWithStatus (ctx , t , cc , errAcceptAndClose )
287-
288- // Invoke resource not found - this should result in L7 RPC error with
289- // unavailable receive on serving as a result, should trigger it to go
290- // serving. Poll as watch might not be started yet to trigger resource not
291- // found.
292- loop:
293- for {
294- if err := internal .TriggerXDSResourceNameNotFoundClient .(func (string , string ) error )("RouteConfigResource" , "routeName" ); err != nil {
295- t .Fatalf ("Failed to trigger resource name not found for testing: %v" , err )
296- }
297- select {
298- case <- serving .Done ():
299- break loop
300- case <- ctx .Done ():
301- t .Fatalf ("timed out waiting for serving mode to go serving" )
302- case <- time .After (time .Millisecond ):
303- }
304- }
305- waitForFailedRPCWithStatus (ctx , t , cc , status .New (codes .Unavailable , "error from xDS configuration for matched route configuration" ))
306- }
307-
308- // TestServingModeChanges tests the Server's logic as it transitions from Not
309- // Ready to Ready, then to Not Ready. Before it goes Ready, connections should
310- // be accepted and closed. After it goes ready, RPC's should proceed as normal
311- // according to matched route configuration. After it transitions back into not
312- // ready (through an explicit LDS Resource Not Found), previously running RPC's
313- // should be gracefully closed and still work, and new RPC's should fail.
314- func (s ) TestServingModeChanges (t * testing.T ) {
315- managementServer , nodeID , bootstrapContents , _ , cleanup := e2e .SetupManagementServer (t , e2e.ManagementServerOptions {})
316- defer cleanup ()
317- lis , err := testutils .LocalTCPListener ()
318- if err != nil {
319- t .Fatalf ("testutils.LocalTCPListener() failed: %v" , err )
320- }
321- // Setup the management server to respond with a listener resource that
322- // specifies a route name to watch. Due to not having received the full
323- // configuration, this should cause the server to be in mode Serving.
324- host , port , err := hostPortFromListener (lis )
325- if err != nil {
326- t .Fatalf ("failed to retrieve host and port of server: %v" , err )
327- }
328-
329- listener := e2e .DefaultServerListenerWithRouteConfigName (host , port , e2e .SecurityLevelNone , "routeName" )
330- resources := e2e.UpdateOptions {
331- NodeID : nodeID ,
332- Listeners : []* v3listenerpb.Listener {listener },
333- SkipValidation : true ,
334- }
335-
336- ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
337- defer cancel ()
338- if err := managementServer .Update (ctx , resources ); err != nil {
339- t .Fatal (err )
340- }
341-
342- serving := grpcsync .NewEvent ()
343- modeChangeOpt := xds .ServingModeCallback (func (addr net.Addr , args xds.ServingModeChangeArgs ) {
344- t .Logf ("serving mode for listener %q changed to %q, err: %v" , addr .String (), args .Mode , args .Err )
345- if args .Mode == connectivity .ServingModeServing {
346- serving .Fire ()
347- }
348- })
349-
350- server , err := xds .NewGRPCServer (grpc .Creds (insecure .NewCredentials ()), modeChangeOpt , xds .BootstrapContentsForTesting (bootstrapContents ))
351- if err != nil {
352- t .Fatalf ("Failed to create an xDS enabled gRPC server: %v" , err )
353- }
354- defer server .Stop ()
355- testgrpc .RegisterTestServiceServer (server , & testService {})
356- go func () {
357- if err := server .Serve (lis ); err != nil {
358- t .Errorf ("Serve() failed: %v" , err )
359- }
360- }()
361- cc , err := grpc .NewClient (lis .Addr ().String (), grpc .WithTransportCredentials (insecure .NewCredentials ()))
362- if err != nil {
363- t .Fatalf ("failed to dial local test server: %v" , err )
364- }
365- defer cc .Close ()
366-
367- waitForFailedRPCWithStatus (ctx , t , cc , errAcceptAndClose )
368- routeConfig := e2e .RouteConfigNonForwardingAction ("routeName" )
369- resources = e2e.UpdateOptions {
370- NodeID : nodeID ,
371- Listeners : []* v3listenerpb.Listener {listener },
372- Routes : []* v3routepb.RouteConfiguration {routeConfig },
373- }
374- defer cancel ()
375- if err := managementServer .Update (ctx , resources ); err != nil {
376- t .Fatal (err )
377- }
378-
379- select {
380- case <- ctx .Done ():
381- t .Fatal ("timeout waiting for the xDS Server to go Serving" )
382- case <- serving .Done ():
383- }
384-
385- // A unary RPC should work once it transitions into serving. (need this same
386- // assertion from LDS resource not found triggering it).
387- waitForSuccessfulRPC (ctx , t , cc )
388-
389- // Start a stream before switching the server to not serving. Due to the
390- // stream being created before the graceful stop of the underlying
391- // connection, it should be able to continue even after the server switches
392- // to not serving.
393- c := testgrpc .NewTestServiceClient (cc )
394- stream , err := c .FullDuplexCall (ctx )
395- if err != nil {
396- t .Fatalf ("cc.FullDuplexCall failed: %f" , err )
397- }
398-
399- // Invoke the lds resource not found - this should cause the server to
400- // switch to not serving. This should gracefully drain connections, and fail
401- // RPC's after. (how to assert accepted + closed) does this make it's way to
402- // application layer? (should work outside of resource not found...
403-
404- // Invoke LDS Resource not found here (tests graceful close)
405- if err := internal .TriggerXDSResourceNameNotFoundClient .(func (string , string ) error )("ListenerResource" , listener .GetName ()); err != nil {
406- t .Fatalf ("Failed to trigger resource name not found for testing: %v" , err )
407- }
408-
409- // New RPCs on that connection should eventually start failing. Due to
410- // Graceful Stop any started streams continue to work.
411- if err = stream .Send (& testpb.StreamingOutputCallRequest {}); err != nil {
412- t .Fatalf ("stream.Send() failed: %v, should continue to work due to graceful stop" , err )
413- }
414- if err = stream .CloseSend (); err != nil {
415- t .Fatalf ("stream.CloseSend() failed: %v, should continue to work due to graceful stop" , err )
416- }
417- if _ , err = stream .Recv (); err != io .EOF {
418- t .Fatalf ("unexpected error: %v, expected an EOF error" , err )
419- }
420-
421- // New RPCs on that connection should eventually start failing.
422- waitForFailedRPCWithStatus (ctx , t , cc , errAcceptAndClose )
423- }
424-
425226// TestMultipleUpdatesImmediatelySwitch tests the case where you get an LDS
426227// specifying RDS A, B, and C (with A being matched to). The Server should be in
427228// not serving until it receives all 3 RDS Configurations, and then transition
0 commit comments