Skip to content

Commit 474c6d4

Browse files
committed
util: duplicate RoundRobinLoadBalancerTest.pickAfterStateChange for new pick-first
PickFirstLeafLoadBalancer does not trigger a second refreshNameResolution when transitioning from TRANSIENT_FAILURE to IDLE during backoff. Duplicate pickAfterStateChange to verify both old and new PF behaviors. TAG=agy CONV=2b34d6af-c0df-46b4-8326-2dea3641f8cc
1 parent e88415f commit 474c6d4

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

‎util/src/test/java/io/grpc/util/RoundRobinLoadBalancerTest.java‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ public void pickAfterResolvedUpdatedHosts() throws Exception {
230230

231231
@Test
232232
public void pickAfterStateChange() throws Exception {
233+
PickFirstLoadBalancerProviderAccessor.setEnableNewPickFirst(false);
233234
InOrder inOrder = inOrder(mockHelper);
234235
Status addressesAcceptanceStatus =
235236
acceptAddresses(Arrays.asList(servers.get(0)), Attributes.EMPTY);
@@ -263,6 +264,42 @@ public void pickAfterStateChange() throws Exception {
263264
AbstractTestHelper.verifyNoMoreMeaningfulInteractions(mockHelper);
264265
}
265266

267+
@Test
268+
public void pickAfterStateChange_newPickFirst() throws Exception {
269+
PickFirstLoadBalancerProviderAccessor.setEnableNewPickFirst(true);
270+
InOrder inOrder = inOrder(mockHelper);
271+
Status addressesAcceptanceStatus =
272+
acceptAddresses(Arrays.asList(servers.get(0)), Attributes.EMPTY);
273+
assertThat(addressesAcceptanceStatus.isOk()).isTrue();
274+
inOrder.verify(mockHelper).createSubchannel(any(CreateSubchannelArgs.class));
275+
276+
// TODO figure out if this method testing the right things
277+
278+
assertThat(subchannels).hasSize(1);
279+
Subchannel subchannel = subchannels.values().iterator().next();
280+
281+
inOrder.verify(mockHelper).updateBalancingState(eq(CONNECTING), eq(EMPTY_PICKER));
282+
283+
deliverSubchannelState(subchannel, ConnectivityStateInfo.forNonError(READY));
284+
inOrder.verify(mockHelper).updateBalancingState(eq(READY), pickerCaptor.capture());
285+
assertThat(pickerCaptor.getValue()).isInstanceOf(ReadyPicker.class);
286+
287+
Status error = Status.UNKNOWN.withDescription("¯\\_(ツ)_//¯");
288+
deliverSubchannelState(subchannel,
289+
ConnectivityStateInfo.forTransientFailure(error));
290+
AbstractTestHelper.refreshInvokedAndUpdateBS(
291+
inOrder, TRANSIENT_FAILURE, mockHelper, pickerCaptor);
292+
assertThat(pickerCaptor.getValue().pickSubchannel(mockArgs).getStatus()).isEqualTo(error);
293+
294+
deliverSubchannelState(subchannel, ConnectivityStateInfo.forNonError(IDLE));
295+
inOrder.verify(mockHelper, never()).refreshNameResolution();
296+
inOrder.verify(mockHelper, never())
297+
.updateBalancingState(eq(TRANSIENT_FAILURE), any(SubchannelPicker.class));
298+
299+
verify(subchannel, atLeastOnce()).requestConnection();
300+
AbstractTestHelper.verifyNoMoreMeaningfulInteractions(mockHelper);
301+
}
302+
266303
@Test
267304
public void ignoreShutdownSubchannelStateChange() {
268305
InOrder inOrder = inOrder(mockHelper);

0 commit comments

Comments
 (0)