@@ -3331,6 +3331,43 @@ public void useIndependentRpcContext() {
33313331 }
33323332 }
33333333
3334+ @ Test
3335+ public void streamClosedWithNoResponse () {
3336+ xdsClient .watchXdsResource (XdsListenerResource .getInstance (),LDS_RESOURCE , ldsResourceWatcher );
3337+ xdsClient .watchXdsResource (XdsRouteConfigureResource .getInstance (),RDS_RESOURCE ,
3338+ rdsResourceWatcher );
3339+ DiscoveryRpcCall call = resourceDiscoveryCalls .poll ();
3340+ // Management server closes the RPC stream before sending any response.
3341+ call .sendCompleted ();
3342+ verify (ldsResourceWatcher , Mockito .timeout (1000 ).times (1 ))
3343+ .onError (errorCaptor .capture ());
3344+ verifyStatusWithNodeId (errorCaptor .getValue (), Code .UNAVAILABLE ,
3345+ "ADS stream closed with OK before receiving a response" );
3346+ verify (rdsResourceWatcher ).onError (errorCaptor .capture ());
3347+ verifyStatusWithNodeId (errorCaptor .getValue (), Code .UNAVAILABLE ,
3348+ "ADS stream closed with OK before receiving a response" );
3349+ }
3350+
3351+ @ Test
3352+ public void streamClosedAfterSendingResponses () {
3353+ xdsClient .watchXdsResource (XdsListenerResource .getInstance (),LDS_RESOURCE , ldsResourceWatcher );
3354+ xdsClient .watchXdsResource (XdsRouteConfigureResource .getInstance (),RDS_RESOURCE ,
3355+ rdsResourceWatcher );
3356+ DiscoveryRpcCall call = resourceDiscoveryCalls .poll ();
3357+ ScheduledTask ldsResourceTimeout =
3358+ Iterables .getOnlyElement (fakeClock .getPendingTasks (LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER ));
3359+ ScheduledTask rdsResourceTimeout =
3360+ Iterables .getOnlyElement (fakeClock .getPendingTasks (RDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER ));
3361+ call .sendResponse (LDS , testListenerRds , VERSION_1 , "0000" );
3362+ assertThat (ldsResourceTimeout .isCancelled ()).isTrue ();
3363+ call .sendResponse (RDS , testRouteConfig , VERSION_1 , "0000" );
3364+ assertThat (rdsResourceTimeout .isCancelled ()).isTrue ();
3365+ // Management server closes the RPC stream after sending responses.
3366+ call .sendCompleted ();
3367+ verify (ldsResourceWatcher , never ()).onError (errorCaptor .capture ());
3368+ verify (rdsResourceWatcher , never ()).onError (errorCaptor .capture ());
3369+ }
3370+
33343371 @ Test
33353372 public void streamClosedAndRetryWithBackoff () {
33363373 InOrder inOrder = Mockito .inOrder (backoffPolicyProvider , backoffPolicy1 , backoffPolicy2 );
@@ -3408,10 +3445,10 @@ public void streamClosedAndRetryWithBackoff() {
34083445 call .sendError (Status .DEADLINE_EXCEEDED .asException ());
34093446 verify (ldsResourceWatcher , times (2 )).onError (errorCaptor .capture ());
34103447 verify (rdsResourceWatcher , times (2 )).onError (errorCaptor .capture ());
3411- verify (cdsResourceWatcher , times (3 )).onError (errorCaptor .capture ());
3412- verifyStatusWithNodeId (errorCaptor .getValue (), Code .DEADLINE_EXCEEDED , "" );
3413- verify (edsResourceWatcher , times (3 )).onError (errorCaptor .capture ());
3414- verifyStatusWithNodeId (errorCaptor .getValue (), Code .DEADLINE_EXCEEDED , "" );
3448+ verify (cdsResourceWatcher , times (2 )).onError (errorCaptor .capture ());
3449+ verifyStatusWithNodeId (errorCaptor .getValue (), Code .UNAVAILABLE , errorMsg );
3450+ verify (edsResourceWatcher , times (2 )).onError (errorCaptor .capture ());
3451+ verifyStatusWithNodeId (errorCaptor .getValue (), Code .UNAVAILABLE , errorMsg );
34153452
34163453 // Reset backoff sequence and retry after backoff.
34173454 inOrder .verify (backoffPolicyProvider ).get ();
@@ -3430,9 +3467,9 @@ public void streamClosedAndRetryWithBackoff() {
34303467 call .sendError (Status .UNAVAILABLE .asException ());
34313468 verify (ldsResourceWatcher , times (2 )).onError (errorCaptor .capture ());
34323469 verify (rdsResourceWatcher , times (2 )).onError (errorCaptor .capture ());
3433- verify (cdsResourceWatcher , times (4 )).onError (errorCaptor .capture ());
3470+ verify (cdsResourceWatcher , times (3 )).onError (errorCaptor .capture ());
34343471 verifyStatusWithNodeId (errorCaptor .getValue (), Code .UNAVAILABLE , "" );
3435- verify (edsResourceWatcher , times (4 )).onError (errorCaptor .capture ());
3472+ verify (edsResourceWatcher , times (3 )).onError (errorCaptor .capture ());
34363473 verifyStatusWithNodeId (errorCaptor .getValue (), Code .UNAVAILABLE , "" );
34373474
34383475 // Retry after backoff.
@@ -3516,10 +3553,8 @@ public void streamClosedAndRetryRestartsResourceInitialFetchTimerForUnresolvedRe
35163553 assertThat (edsResourceTimeout .isCancelled ()).isTrue ();
35173554 verify (ldsResourceWatcher , never ()).onError (errorCaptor .capture ());
35183555 verify (rdsResourceWatcher , never ()).onError (errorCaptor .capture ());
3519- verify (cdsResourceWatcher ).onError (errorCaptor .capture ());
3520- verifyStatusWithNodeId (errorCaptor .getValue (), Code .UNAVAILABLE , "" );
3521- verify (edsResourceWatcher ).onError (errorCaptor .capture ());
3522- verifyStatusWithNodeId (errorCaptor .getValue (), Code .UNAVAILABLE , "" );
3556+ verify (cdsResourceWatcher , never ()).onError (errorCaptor .capture ());
3557+ verify (edsResourceWatcher , never ()).onError (errorCaptor .capture ());
35233558
35243559 fakeClock .forwardNanos (10L );
35253560 assertThat (fakeClock .getPendingTasks (LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER )).hasSize (0 );
0 commit comments