Skip to content

Commit e88415f

Browse files
committed
rls: duplicate RlsLoadBalancerTest to test old and new pick-first
Separate lb_working_withDefaultTarget_rlsResponding into legacy and new pick-first test variants with the appropriate InOrder createSubchannel verifications. TAG=agy CONV=2b34d6af-c0df-46b4-8326-2dea3641f8cc
1 parent 37c510c commit e88415f

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

‎rls/src/test/java/io/grpc/rls/RlsLoadBalancerTest.java‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
import io.grpc.inprocess.InProcessServerBuilder;
7474
import io.grpc.internal.FakeClock;
7575
import io.grpc.internal.JsonParser;
76+
import io.grpc.internal.PickFirstLoadBalancerProvider;
77+
import io.grpc.internal.PickFirstLoadBalancerProviderAccessor;
7678
import io.grpc.internal.PickSubchannelArgsImpl;
7779
import io.grpc.internal.testing.StreamRecorder;
7880
import io.grpc.lookup.v1.RouteLookupServiceGrpc;
@@ -118,6 +120,8 @@ public class RlsLoadBalancerTest {
118120
public final GrpcCleanupRule grpcCleanupRule = new GrpcCleanupRule();
119121
@Rule
120122
public final MockitoRule mocks = MockitoJUnit.rule();
123+
private final boolean defaultNewPickFirst =
124+
PickFirstLoadBalancerProvider.isEnabledNewPickFirst();
121125
private final RlsLoadBalancerProvider provider = new RlsLoadBalancerProvider();
122126
private final FakeClock fakeClock = new FakeClock();
123127
private final SynchronizationContext syncContext =
@@ -201,6 +205,7 @@ public CachingRlsLbClient.Builder get() {
201205
@After
202206
public void tearDown() {
203207
rlsLb.shutdown();
208+
PickFirstLoadBalancerProviderAccessor.setEnableNewPickFirst(defaultNewPickFirst);
204209
}
205210

206211
@Test
@@ -247,6 +252,7 @@ public void lb_serverStatusCodeConversion() throws Exception {
247252

248253
@Test
249254
public void lb_working_withDefaultTarget_rlsResponding() throws Exception {
255+
PickFirstLoadBalancerProviderAccessor.setEnableNewPickFirst(false);
250256
helper.getSynchronizationContext().execute(() -> {
251257
try {
252258
deliverResolvedAddresses();
@@ -315,6 +321,78 @@ public void lb_working_withDefaultTarget_rlsResponding() throws Exception {
315321
verifyLongCounterAdd("grpc.lb.rls.target_picks", 1, 1, "wilderness", "fail");
316322
}
317323

324+
@Test
325+
public void lb_working_withDefaultTarget_rlsResponding_newPickFirst() throws Exception {
326+
PickFirstLoadBalancerProviderAccessor.setEnableNewPickFirst(true);
327+
helper.getSynchronizationContext().execute(() -> {
328+
try {
329+
deliverResolvedAddresses();
330+
} catch (Exception e) {
331+
throw new RuntimeException(e);
332+
}
333+
});
334+
InOrder inOrder = inOrder(helper);
335+
inOrder.verify(helper)
336+
.updateBalancingState(eq(ConnectivityState.CONNECTING), pickerCaptor.capture());
337+
inOrder.verify(helper).createSubchannel(any(CreateSubchannelArgs.class));
338+
SubchannelPicker picker = pickerCaptor.getValue();
339+
// Warm-up pick; will be queued
340+
PickResult res = picker.pickSubchannel(searchSubchannelArgs);
341+
assertThat(res.getStatus().isOk()).isTrue();
342+
assertThat(res.getSubchannel()).isNull();
343+
assertThat(res.getDelayType()).isEqualTo("rls_lookup_pending");
344+
assertThat(res.getDelayReason()).contains("Route Lookup Service query pending");
345+
// Cache is warm, but still unconnected
346+
res = picker.pickSubchannel(searchSubchannelArgs);
347+
inOrder.verify(helper).createSubchannel(any(CreateSubchannelArgs.class));
348+
inOrder.verify(helper, atLeast(0))
349+
.updateBalancingState(eq(ConnectivityState.CONNECTING), any(SubchannelPicker.class));
350+
inOrder.verify(helper, atLeast(0)).getSynchronizationContext();
351+
inOrder.verify(helper, atLeast(0)).getScheduledExecutorService();
352+
inOrder.verify(helper, atLeast(0)).getMetricRecorder();
353+
inOrder.verify(helper, atLeast(0)).getChannelTarget();
354+
inOrder.verifyNoMoreInteractions();
355+
356+
assertThat(res.getStatus().isOk()).isTrue();
357+
assertThat(subchannels).hasSize(2); // includes fallback sub-channel
358+
FakeSubchannel searchSubchannel = subchannels.getLast();
359+
assertThat(subchannelIsReady(searchSubchannel)).isFalse();
360+
361+
searchSubchannel.updateState(ConnectivityStateInfo.forNonError(ConnectivityState.READY));
362+
inOrder.verify(helper)
363+
.updateBalancingState(eq(ConnectivityState.READY), pickerCaptor.capture());
364+
inOrder.verifyNoMoreInteractions();
365+
res = picker.pickSubchannel(searchSubchannelArgs);
366+
assertThat(subchannelIsReady(res.getSubchannel())).isTrue();
367+
assertThat(res.getSubchannel()).isSameInstanceAs(searchSubchannel);
368+
verifyLongCounterAdd("grpc.lb.rls.target_picks", 1, 1, "wilderness", "complete");
369+
370+
// rescue should be pending status although the overall channel state is READY
371+
res = picker.pickSubchannel(rescueSubchannelArgs);
372+
inOrder.verify(helper).createSubchannel(any(CreateSubchannelArgs.class));
373+
// other rls picker itself is ready due to first channel.
374+
assertThat(res.getStatus().isOk()).isTrue();
375+
assertThat(subchannelIsReady(res.getSubchannel())).isFalse();
376+
assertThat(subchannels).hasSize(3); // includes fallback sub-channel
377+
FakeSubchannel rescueSubchannel = subchannels.getLast();
378+
379+
// search subchannel is down, rescue subchannel is connecting
380+
searchSubchannel.updateState(ConnectivityStateInfo.forTransientFailure(Status.UNAVAILABLE));
381+
inOrder.verify(helper)
382+
.updateBalancingState(eq(ConnectivityState.CONNECTING), pickerCaptor.capture());
383+
384+
rescueSubchannel.updateState(ConnectivityStateInfo.forNonError(ConnectivityState.READY));
385+
inOrder.verify(helper)
386+
.updateBalancingState(eq(ConnectivityState.READY), pickerCaptor.capture());
387+
388+
// search again, verify that it doesn't use fallback, since RLS server responded, even though
389+
// subchannel is in failure mode
390+
res = picker.pickSubchannel(searchSubchannelArgs);
391+
assertThat(res.getStatus().getCode()).isEqualTo(Status.Code.UNAVAILABLE);
392+
assertThat(subchannelIsReady(res.getSubchannel())).isFalse();
393+
verifyLongCounterAdd("grpc.lb.rls.target_picks", 1, 1, "wilderness", "fail");
394+
}
395+
318396
@Test
319397
public void fallbackWithDelay_succeeds() throws Exception {
320398
fakeRlsServerImpl.setResponseDelay(100, TimeUnit.MILLISECONDS);

0 commit comments

Comments
 (0)