134134import org .mockito .junit .MockitoJUnit ;
135135import org .mockito .junit .MockitoRule ;
136136import org .mockito .stubbing .Answer ;
137+ import org .mockito .verification .VerificationMode ;
137138
138139/**
139140 * Tests for {@link XdsClientImpl}.
@@ -2766,8 +2767,7 @@ public void edsCleanupNonceAfterUnsubscription() {
27662767 xdsClient .watchXdsResource (XdsEndpointResource .getInstance (), "A.1" , edsResourceWatcher );
27672768 DiscoveryRpcCall call = resourceDiscoveryCalls .poll ();
27682769 assertThat (call ).isNotNull ();
2769- verifyResourceMetadataRequested (EDS , "A.1" );
2770- verifySubscribedResourcesMetadataSizes (0 , 0 , 0 , 1 );
2770+ call .verifyRequest (EDS , "A.1" , "" , "" , NODE );
27712771
27722772 // EDS -> {A.1}, version 1
27732773 List <Message > dropOverloads = ImmutableList .of ();
@@ -2776,19 +2776,17 @@ public void edsCleanupNonceAfterUnsubscription() {
27762776 "A.1" , Any .pack (mf .buildClusterLoadAssignment ("A.1" , endpointsV1 , dropOverloads )));
27772777 call .sendResponse (EDS , resourcesV1 .values ().asList (), VERSION_1 , "0000" );
27782778 // {A.1} -> ACK, version 1
2779- verifyResourceMetadataAcked (EDS , "A.1" , resourcesV1 .get ("A.1" ), VERSION_1 , TIME_INCREMENT );
27802779 call .verifyRequest (EDS , "A.1" , VERSION_1 , "0000" , NODE );
27812780 verify (edsResourceWatcher , times (1 )).onChanged (any ());
27822781
27832782 // trigger an EDS resource unsubscription.
2784- // This would probably be caused by CDS PUSH(let's say event e1) in the real world.
2785- // Then there can be a potential data race between
2786- // 1) the EDS unsubscription caused by CDS PUSH e1 (client-side) and,
2787- // 2) the immediate EDS PUSH from XdsServer (server-side) after CDS PUSH e1 (event e2).
27882783 xdsClient .cancelXdsResourceWatch (XdsEndpointResource .getInstance (), "A.1" , edsResourceWatcher );
27892784 verifySubscribedResourcesMetadataSizes (0 , 0 , 0 , 0 );
2790- // The nonce has been removed
2791- assertThat (getNonceForResourceType (xdsClient , xdsServerInfo , EDS )).isNull ();
2785+
2786+ // When re-subscribing, the version and nonce were properly forgotten, so the request is the
2787+ // same as the initial request
2788+ xdsClient .watchXdsResource (XdsEndpointResource .getInstance (), "A.1" , edsResourceWatcher );
2789+ call .verifyRequest (EDS , "A.1" , "" , "" , NODE , Mockito .timeout (2000 ).times (2 ));
27922790 }
27932791
27942792 @ Test
@@ -3821,10 +3819,22 @@ protected abstract static class DiscoveryRpcCall {
38213819
38223820 protected void verifyRequest (
38233821 XdsResourceType <?> type , List <String > resources , String versionInfo , String nonce ,
3824- Node node ) {
3822+ Node node , VerificationMode verificationMode ) {
38253823 throw new UnsupportedOperationException ();
38263824 }
38273825
3826+ protected void verifyRequest (
3827+ XdsResourceType <?> type , List <String > resources , String versionInfo , String nonce ,
3828+ Node node ) {
3829+ verifyRequest (type , resources , versionInfo , nonce , node , Mockito .timeout (2000 ));
3830+ }
3831+
3832+ protected void verifyRequest (
3833+ XdsResourceType <?> type , String resource , String versionInfo , String nonce ,
3834+ Node node , VerificationMode verificationMode ) {
3835+ verifyRequest (type , ImmutableList .of (resource ), versionInfo , nonce , node , verificationMode );
3836+ }
3837+
38283838 protected void verifyRequest (
38293839 XdsResourceType <?> type , String resource , String versionInfo , String nonce , Node node ) {
38303840 verifyRequest (type , ImmutableList .of (resource ), versionInfo , nonce , node );
0 commit comments