-
Notifications
You must be signed in to change notification settings - Fork 3.9k
xds: Update logic so that an error being reported when stream is closed gets propagated to subscribers #9827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
834df4f
7865536
f62c91a
9f77e0f
b5783fc
ea01796
88c760d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static com.google.common.truth.Truth.assertWithMessage; | ||
import static io.grpc.xds.XdsClientImpl.XdsChannelFactory.DEFAULT_XDS_CHANNEL_FACTORY; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.isA; | ||
import static org.mockito.Mockito.mock; | ||
|
@@ -70,6 +71,7 @@ | |
import io.grpc.stub.StreamObserver; | ||
import io.grpc.testing.GrpcCleanupRule; | ||
import io.grpc.xds.Bootstrapper.AuthorityInfo; | ||
import io.grpc.xds.Bootstrapper.BootstrapInfo; | ||
import io.grpc.xds.Bootstrapper.CertificateProviderInfo; | ||
import io.grpc.xds.Bootstrapper.ServerInfo; | ||
import io.grpc.xds.Endpoints.DropOverload; | ||
|
@@ -107,13 +109,15 @@ | |
import java.util.concurrent.atomic.AtomicBoolean; | ||
import javax.annotation.Nullable; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Assume; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.ArgumentMatchers; | ||
import org.mockito.Captor; | ||
import org.mockito.InOrder; | ||
import org.mockito.Mock; | ||
|
@@ -3573,13 +3577,18 @@ public void sendingToStoppedServer() throws Exception { | |
.build() | ||
.start()); | ||
fakeClock.forwardTime(5, TimeUnit.SECONDS); | ||
verify(ldsResourceWatcher, never()).onResourceDoesNotExist(LDS_RESOURCE); | ||
fakeClock.forwardTime(20, TimeUnit.SECONDS); // Trigger rpcRetryTimer | ||
DiscoveryRpcCall call = resourceDiscoveryCalls.poll(3, TimeUnit.SECONDS); | ||
if (call == null) { // The first rpcRetry may have happened before the channel was ready | ||
fakeClock.forwardTime(50, TimeUnit.SECONDS); | ||
call = resourceDiscoveryCalls.poll(3, TimeUnit.SECONDS); | ||
} | ||
|
||
// NOTE: There is a ScheduledExecutorService that may get involved due to the reconnect | ||
// so you cannot rely on the logic being single threaded. The timeout() in verifyRequest | ||
// is therefore necessary to avoid flakiness. | ||
// Send a response and do verifications | ||
verify(ldsResourceWatcher, never()).onResourceDoesNotExist(LDS_RESOURCE); | ||
call.sendResponse(LDS, mf.buildWrappedResource(testListenerVhosts), VERSION_1, "0001"); | ||
call.verifyRequest(LDS, LDS_RESOURCE, VERSION_1, "0001", NODE); | ||
verify(ldsResourceWatcher).onChanged(ldsUpdateCaptor.capture()); | ||
|
@@ -3592,6 +3601,75 @@ public void sendingToStoppedServer() throws Exception { | |
} | ||
} | ||
|
||
@Test | ||
public void sendToBadUrl() throws Exception { | ||
// Setup xdsClient to fail on stream creation | ||
XdsClientImpl client = createXdsClient("some. garbage"); | ||
|
||
try { | ||
client.watchXdsResource(XdsListenerResource.getInstance(), LDS_RESOURCE, ldsResourceWatcher); | ||
fakeClock.forwardTime(20, TimeUnit.SECONDS); | ||
} catch (AssertionError e) { | ||
assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class); | ||
return; | ||
} | ||
Assert.fail("Expected exception for bad url not thrown"); | ||
verify(ldsResourceWatcher).onError(errorCaptor.capture()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these lines necessary after Assert.fail()? Also they seem incomplete about error verification. Also it looks the test are not strictly testing the "narrowing down close condition" change at all. It is a bit redundant with test case The IllegalArgument may not be related to stream creation failure but about the xdstp thing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put this in to verify that a malformed URL got processed in the expected way which was different than how a nonexistent host was handled. It had nothing to do with close or retry. Handling unknown URLs is what caused the user's problem and I noticed that both unknown and invalid url cases were missing. Cleaned up the lines after the Assert.fail. |
||
assertThat(fakeClock.getPendingTasks(LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isNotEmpty(); | ||
} | ||
|
||
@Test | ||
public void sendToNonexistentHost() throws Exception { | ||
// Setup xdsClient to fail on stream creation | ||
XdsClientImpl client = createXdsClient("some.garbage"); | ||
client.watchXdsResource(XdsListenerResource.getInstance(), LDS_RESOURCE, ldsResourceWatcher); | ||
fakeClock.forwardTime(20, TimeUnit.SECONDS); | ||
|
||
verify(ldsResourceWatcher, Mockito.timeout(5000).times(1)).onError(ArgumentMatchers.any()); | ||
fakeClock.forwardTime(50, TimeUnit.SECONDS); // Trigger rpcRetry if appropriate | ||
assertThat(fakeClock.getPendingTasks(LDS_RESOURCE_FETCH_TIMEOUT_TASK_FILTER)).isEmpty(); | ||
// Get rid of rpcRetryTask that should have been scheduled since still cannot talk to server | ||
for (ScheduledTask task : fakeClock.getPendingTasks()) { | ||
task.cancel(true); | ||
} | ||
} | ||
|
||
private XdsClientImpl createXdsClient(String serverUri) { | ||
BootstrapInfo bootstrapInfo = buildBootStrap(serverUri); | ||
return new XdsClientImpl( | ||
DEFAULT_XDS_CHANNEL_FACTORY, | ||
bootstrapInfo, | ||
Context.ROOT, | ||
fakeClock.getScheduledExecutorService(), | ||
backoffPolicyProvider, | ||
fakeClock.getStopwatchSupplier(), | ||
timeProvider, | ||
tlsContextManager); | ||
} | ||
|
||
private BootstrapInfo buildBootStrap(String serverUri) { | ||
|
||
ServerInfo xdsServerInfo = ServerInfo.create(serverUri, CHANNEL_CREDENTIALS, | ||
ignoreResourceDeletion()); | ||
|
||
return Bootstrapper.BootstrapInfo.builder() | ||
.servers(Collections.singletonList(xdsServerInfo)) | ||
.node(NODE) | ||
.authorities(ImmutableMap.of( | ||
"authority.xds.com", | ||
AuthorityInfo.create( | ||
"xdstp://authority.xds.com/envoy.config.listener.v3.Listener/%s", | ||
ImmutableList.of(Bootstrapper.ServerInfo.create( | ||
SERVER_URI_CUSTOME_AUTHORITY, CHANNEL_CREDENTIALS))), | ||
"", | ||
AuthorityInfo.create( | ||
"xdstp:///envoy.config.listener.v3.Listener/%s", | ||
ImmutableList.of(Bootstrapper.ServerInfo.create( | ||
SERVER_URI_EMPTY_AUTHORITY, CHANNEL_CREDENTIALS))))) | ||
.certProviders(ImmutableMap.of("cert-instance-name", | ||
CertificateProviderInfo.create("file-watcher", ImmutableMap.<String, Object>of()))) | ||
.build(); | ||
} | ||
|
||
private <T extends ResourceUpdate> DiscoveryRpcCall startResourceWatcher( | ||
XdsResourceType<T> type, String name, ResourceWatcher<T> watcher) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.