mirror of https://github.com/grpc/grpc-java.git
core/test: re-enable tests for panic mode. (#5879)
panic mode was temporarily disabled by #4152 and re-enabled by #4245, but the tests were not. This has caused a few test code that was broken but not executed at all.
This commit is contained in:
parent
e795f14bed
commit
aa783ee252
|
|
@ -791,6 +791,11 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
||||||
channelStateManager.gotoState(TRANSIENT_FAILURE);
|
channelStateManager.gotoState(TRANSIENT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean isInPanicMode() {
|
||||||
|
return panicMode;
|
||||||
|
}
|
||||||
|
|
||||||
// Called from syncContext
|
// Called from syncContext
|
||||||
private void updateSubchannelPicker(SubchannelPicker newPicker) {
|
private void updateSubchannelPicker(SubchannelPicker newPicker) {
|
||||||
subchannelPicker = newPicker;
|
subchannelPicker = newPicker;
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,6 @@ import java.util.logging.Logger;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Assume;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@ -269,6 +268,7 @@ public class ManagedChannelImplTest {
|
||||||
private ChannelBuilder channelBuilder;
|
private ChannelBuilder channelBuilder;
|
||||||
private boolean requestConnection = true;
|
private boolean requestConnection = true;
|
||||||
private BlockingQueue<MockClientTransportInfo> transports;
|
private BlockingQueue<MockClientTransportInfo> transports;
|
||||||
|
private boolean panicExpected;
|
||||||
|
|
||||||
private ArgumentCaptor<ClientStreamListener> streamListenerCaptor =
|
private ArgumentCaptor<ClientStreamListener> streamListenerCaptor =
|
||||||
ArgumentCaptor.forClass(ClientStreamListener.class);
|
ArgumentCaptor.forClass(ClientStreamListener.class);
|
||||||
|
|
@ -338,6 +338,9 @@ public class ManagedChannelImplTest {
|
||||||
assertTrue(timer.getDueTasks() + " should be empty", timer.getDueTasks().isEmpty());
|
assertTrue(timer.getDueTasks() + " should be empty", timer.getDueTasks().isEmpty());
|
||||||
assertEquals(executor.getPendingTasks() + " should be empty", 0, executor.numPendingTasks());
|
assertEquals(executor.getPendingTasks() + " should be empty", 0, executor.numPendingTasks());
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
|
if (!panicExpected) {
|
||||||
|
assertFalse(channel.isInPanicMode());
|
||||||
|
}
|
||||||
channel.shutdownNow();
|
channel.shutdownNow();
|
||||||
channel = null;
|
channel = null;
|
||||||
}
|
}
|
||||||
|
|
@ -405,15 +408,8 @@ public class ManagedChannelImplTest {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void createSubchannel_old_propagateSubchannelStatesToOldApi() {
|
public void createSubchannel_old_propagateSubchannelStatesToOldApi() {
|
||||||
createChannel();
|
createChannel();
|
||||||
final AtomicReference<Subchannel> subchannelCapture = new AtomicReference<>();
|
|
||||||
helper.getSynchronizationContext().execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
subchannelCapture.set(helper.createSubchannel(addressGroup, Attributes.EMPTY));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Subchannel subchannel = subchannelCapture.get();
|
Subchannel subchannel = helper.createSubchannel(addressGroup, Attributes.EMPTY);
|
||||||
subchannel.requestConnection();
|
subchannel.requestConnection();
|
||||||
|
|
||||||
verify(mockTransportFactory)
|
verify(mockTransportFactory)
|
||||||
|
|
@ -427,6 +423,15 @@ public class ManagedChannelImplTest {
|
||||||
|
|
||||||
verify(mockLoadBalancer).handleSubchannelState(
|
verify(mockLoadBalancer).handleSubchannelState(
|
||||||
same(subchannel), eq(ConnectivityStateInfo.forNonError(READY)));
|
same(subchannel), eq(ConnectivityStateInfo.forNonError(READY)));
|
||||||
|
|
||||||
|
channel.shutdown();
|
||||||
|
verify(mockLoadBalancer).shutdown();
|
||||||
|
subchannel.shutdown();
|
||||||
|
|
||||||
|
verify(mockLoadBalancer, atLeast(0)).canHandleEmptyAddressListFromNameResolution();
|
||||||
|
verify(mockLoadBalancer, atLeast(0)).handleNameResolutionError(any(Status.class));
|
||||||
|
// handleSubchannelState() should not be called after shutdown()
|
||||||
|
verifyNoMoreInteractions(mockLoadBalancer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -773,9 +778,17 @@ public class ManagedChannelImplTest {
|
||||||
|
|
||||||
channel.shutdown();
|
channel.shutdown();
|
||||||
verify(mockLoadBalancer).shutdown();
|
verify(mockLoadBalancer).shutdown();
|
||||||
|
verifyNoMoreInteractions(stateListener1, stateListener2);
|
||||||
|
|
||||||
// No more callback should be delivered to LoadBalancer after it's shut down
|
// LoadBalancer will normally shutdown all subchannels
|
||||||
|
subchannel1.shutdown();
|
||||||
|
subchannel2.shutdown();
|
||||||
|
|
||||||
|
// No more callback are delivered to LoadBalancer or the state listeners after it's shut down
|
||||||
|
transportInfo1.listener.transportShutdown(Status.UNAVAILABLE);
|
||||||
transportInfo2.listener.transportReady();
|
transportInfo2.listener.transportReady();
|
||||||
|
verifyNoMoreInteractions(stateListener1, stateListener2);
|
||||||
|
|
||||||
resolver.listener.onError(resolutionError);
|
resolver.listener.onError(resolutionError);
|
||||||
resolver.resolved();
|
resolver.resolved();
|
||||||
verifyNoMoreInteractions(mockLoadBalancer);
|
verifyNoMoreInteractions(mockLoadBalancer);
|
||||||
|
|
@ -2213,8 +2226,8 @@ public class ManagedChannelImplTest {
|
||||||
assertEquals(TRANSIENT_FAILURE, channel.getState(true));
|
assertEquals(TRANSIENT_FAILURE, channel.getState(true));
|
||||||
verifyPanicMode(panicReason);
|
verifyPanicMode(panicReason);
|
||||||
|
|
||||||
// No new resolver or balancer are created
|
// Besides the resolver created initially, no new resolver or balancer are created.
|
||||||
verifyNoMoreInteractions(mockLoadBalancerProvider);
|
verify(mockLoadBalancerProvider).newLoadBalancer(any(Helper.class));
|
||||||
assertThat(nameResolverFactory.resolvers).isEmpty();
|
assertThat(nameResolverFactory.resolvers).isEmpty();
|
||||||
|
|
||||||
// A misbehaving balancer that calls updateBalancingState() after it's shut down will not be
|
// A misbehaving balancer that calls updateBalancingState() after it's shut down will not be
|
||||||
|
|
@ -2223,7 +2236,12 @@ public class ManagedChannelImplTest {
|
||||||
verifyPanicMode(panicReason);
|
verifyPanicMode(panicReason);
|
||||||
|
|
||||||
// Cannot be revived by exitIdleMode()
|
// Cannot be revived by exitIdleMode()
|
||||||
|
channel.syncContext.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
channel.exitIdleMode();
|
channel.exitIdleMode();
|
||||||
|
}
|
||||||
|
});
|
||||||
verifyPanicMode(panicReason);
|
verifyPanicMode(panicReason);
|
||||||
|
|
||||||
// Can still shutdown normally
|
// Can still shutdown normally
|
||||||
|
|
@ -2270,11 +2288,11 @@ public class ManagedChannelImplTest {
|
||||||
executor.runDueTasks();
|
executor.runDueTasks();
|
||||||
verifyCallListenerClosed(mockCallListener, Status.Code.INTERNAL, panicReason);
|
verifyCallListenerClosed(mockCallListener, Status.Code.INTERNAL, panicReason);
|
||||||
verifyCallListenerClosed(mockCallListener2, Status.Code.INTERNAL, panicReason);
|
verifyCallListenerClosed(mockCallListener2, Status.Code.INTERNAL, panicReason);
|
||||||
|
panicExpected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyPanicMode(Throwable cause) {
|
private void verifyPanicMode(Throwable cause) {
|
||||||
Assume.assumeTrue("Panic mode disabled to resolve issues with some tests. See #3293", false);
|
panicExpected = true;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ClientCall.Listener<Integer> mockListener =
|
ClientCall.Listener<Integer> mockListener =
|
||||||
(ClientCall.Listener<Integer>) mock(ClientCall.Listener.class);
|
(ClientCall.Listener<Integer>) mock(ClientCall.Listener.class);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue