Skip to content

Commit 09f18f1

Browse files
committed
Clean up version as well; verify traffic to control plane
1 parent 2b636c2 commit 09f18f1

File tree

4 files changed

+25
-45
lines changed

4 files changed

+25
-45
lines changed

xds/src/main/java/io/grpc/xds/client/ControlPlaneClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ void adjustResourceSubscription(XdsResourceType<?> resourceType) {
155155
if (resources != null) {
156156
adsStream.sendDiscoveryRequest(resourceType, resources);
157157
} else {
158-
// cleanup the nonce for the resource type if it's not subscribed to anymore.
158+
// The resource type no longer has subscribing resources; clean up references to it
159+
versions.remove(resourceType);
159160
adsStream.respNonces.remove(resourceType);
160161
}
161162
}

xds/src/test/java/io/grpc/xds/GrpcXdsClientImplTestBase.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
import org.mockito.junit.MockitoJUnit;
135135
import org.mockito.junit.MockitoRule;
136136
import 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);

xds/src/test/java/io/grpc/xds/GrpcXdsClientImplV3Test.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
import org.mockito.ArgumentMatcher;
119119
import org.mockito.InOrder;
120120
import org.mockito.Mockito;
121+
import org.mockito.verification.VerificationMode;
121122

122123
/**
123124
* Tests for {@link XdsClientImpl} with protocol version v3.
@@ -205,8 +206,8 @@ private DiscoveryRpcCallV3(StreamObserver<DiscoveryRequest> requestObserver,
205206
@Override
206207
protected void verifyRequest(
207208
XdsResourceType<?> type, List<String> resources, String versionInfo, String nonce,
208-
EnvoyProtoData.Node node) {
209-
verify(requestObserver, Mockito.timeout(2000)).onNext(argThat(new DiscoveryRequestMatcher(
209+
EnvoyProtoData.Node node, VerificationMode verificationMode) {
210+
verify(requestObserver, verificationMode).onNext(argThat(new DiscoveryRequestMatcher(
210211
node.toEnvoyProtoNode(), versionInfo, resources, type.typeUrl(), nonce, null, null)));
211212
}
212213

xds/src/test/java/io/grpc/xds/client/ControlPlaneClientTestBase.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)