diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java
index 30487e7567..a8e5f69648 100644
--- a/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java
+++ b/interop-testing/src/main/java/io/grpc/testing/integration/AbstractInteropTest.java
@@ -110,7 +110,9 @@ 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.rules.Timeout;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.verification.VerificationMode;
@@ -121,6 +123,9 @@ import org.mockito.verification.VerificationMode;
* New tests should avoid using Mockito to support running on AppEngine.
*/
public abstract class AbstractInteropTest {
+
+ @Rule public final Timeout globalTimeout = Timeout.seconds(30);
+
/** Must be at least {@link #unaryPayloadLength()}, plus some to account for encoding overhead. */
public static final int MAX_MESSAGE_SIZE = 16 * 1024 * 1024;
public static final Metadata.Key METADATA_KEY =
@@ -266,7 +271,7 @@ public abstract class AbstractInteropTest {
return true;
}
- @Test(timeout = 10000)
+ @Test
public void emptyUnary() throws Exception {
assertEquals(EMPTY, blockingStub.emptyCall(EMPTY));
}
@@ -309,7 +314,7 @@ public abstract class AbstractInteropTest {
assertNotEquals(response1, response3);
}
- @Test(timeout = 10000)
+ @Test
public void largeUnary() throws Exception {
assumeEnoughMemory();
final SimpleRequest request = SimpleRequest.newBuilder()
@@ -393,7 +398,7 @@ public abstract class AbstractInteropTest {
* compliant server, this test will exercise the code path for receiving a compressed response but
* cannot itself verify that the response was compressed.
*/
- @Test(timeout = 10000)
+ @Test
public void serverCompressedUnary() throws Exception {
assumeEnoughMemory();
final SimpleRequest responseShouldBeCompressed =
@@ -432,7 +437,7 @@ public abstract class AbstractInteropTest {
}
}
- @Test(timeout = 10000)
+ @Test
public void serverStreaming() throws Exception {
final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
.setResponseType(PayloadType.COMPRESSABLE)
@@ -474,7 +479,7 @@ public abstract class AbstractInteropTest {
assertEquals(goldenResponses, recorder.getValues());
}
- @Test(timeout = 10000)
+ @Test
public void clientStreaming() throws Exception {
final List requests = Arrays.asList(
StreamingInputCallRequest.newBuilder()
@@ -589,7 +594,7 @@ public abstract class AbstractInteropTest {
assertEquals(goldenResponses, recorder.getValues());
}
- @Test(timeout = 10000)
+ @Test
public void pingPong() throws Exception {
final List requests = Arrays.asList(
StreamingOutputCallRequest.newBuilder()
@@ -666,7 +671,7 @@ public abstract class AbstractInteropTest {
assertEquals("Completed", queue.poll(operationTimeoutMillis(), TimeUnit.MILLISECONDS));
}
- @Test(timeout = 10000)
+ @Test
public void emptyStream() throws Exception {
StreamRecorder responseObserver = StreamRecorder.create();
StreamObserver requestObserver
@@ -675,7 +680,7 @@ public abstract class AbstractInteropTest {
responseObserver.awaitCompletion(operationTimeoutMillis(), TimeUnit.MILLISECONDS);
}
- @Test(timeout = 10000)
+ @Test
public void cancelAfterBegin() throws Exception {
StreamRecorder responseObserver = StreamRecorder.create();
StreamObserver requestObserver =
@@ -698,7 +703,7 @@ public abstract class AbstractInteropTest {
}
}
- @Test(timeout = 10000)
+ @Test
public void cancelAfterFirstResponse() throws Exception {
final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
.addResponseParameters(ResponseParameters.newBuilder()
@@ -728,7 +733,7 @@ public abstract class AbstractInteropTest {
}
}
- @Test(timeout = 10000)
+ @Test
public void fullDuplexCallShouldSucceed() throws Exception {
// Build the request.
List responseSizes = Arrays.asList(50, 100, 150, 200);
@@ -769,7 +774,7 @@ public abstract class AbstractInteropTest {
}
}
- @Test(timeout = 10000)
+ @Test
public void halfDuplexCallShouldSucceed() throws Exception {
// Build the request.
List responseSizes = Arrays.asList(50, 100, 150, 200);
@@ -804,7 +809,7 @@ public abstract class AbstractInteropTest {
}
}
- @Test(timeout = 10000)
+ @Test
public void serverStreamingShouldBeFlowControlled() throws Exception {
final StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
.setResponseType(COMPRESSABLE)
@@ -863,7 +868,7 @@ public abstract class AbstractInteropTest {
assertEquals(Status.OK, queue.poll(operationTimeoutMillis(), TimeUnit.MILLISECONDS));
}
- @Test(timeout = 30000)
+ @Test
public void veryLargeRequest() throws Exception {
assumeEnoughMemory();
final SimpleRequest request = SimpleRequest.newBuilder()
@@ -882,7 +887,7 @@ public abstract class AbstractInteropTest {
assertEquals(goldenResponse, blockingStub.unaryCall(request));
}
- @Test(timeout = 30000)
+ @Test
public void veryLargeResponse() throws Exception {
assumeEnoughMemory();
final SimpleRequest request = SimpleRequest.newBuilder()
@@ -898,7 +903,7 @@ public abstract class AbstractInteropTest {
assertEquals(goldenResponse, blockingStub.unaryCall(request));
}
- @Test(timeout = 10000)
+ @Test
public void exchangeMetadataUnaryCall() throws Exception {
TestServiceGrpc.TestServiceBlockingStub stub = blockingStub;
@@ -921,7 +926,7 @@ public abstract class AbstractInteropTest {
Assert.assertEquals(contextValue, trailersCapture.get().get(METADATA_KEY));
}
- @Test(timeout = 10000)
+ @Test
public void exchangeMetadataStreamingCall() throws Exception {
TestServiceGrpc.TestServiceStub stub = asyncStub;
@@ -968,7 +973,7 @@ public abstract class AbstractInteropTest {
Assert.assertEquals(contextValue, trailersCapture.get().get(METADATA_KEY));
}
- @Test(timeout = 10000)
+ @Test
public void sendsTimeoutHeader() {
Assume.assumeTrue("can not capture server side request headers", server != null);
long configuredTimeoutMinutes = 100;
@@ -996,7 +1001,7 @@ public abstract class AbstractInteropTest {
.build()).next();
}
- @Test(timeout = 25000)
+ @Test
public void deadlineExceeded() throws Exception {
// warm up the channel and JVM
blockingStub.emptyCall(Empty.getDefaultInstance());
@@ -1024,7 +1029,7 @@ public abstract class AbstractInteropTest {
}
}
- @Test(timeout = 10000)
+ @Test
public void deadlineExceededServerStreaming() throws Exception {
// warm up the channel and JVM
blockingStub.emptyCall(Empty.getDefaultInstance());
@@ -1057,7 +1062,7 @@ public abstract class AbstractInteropTest {
}
}
- @Test(timeout = 10000)
+ @Test
public void deadlineInPast() throws Exception {
// Test once with idle channel and once with active channel
try {
@@ -1099,7 +1104,7 @@ public abstract class AbstractInteropTest {
}
}
- @Test(timeout = 10000)
+ @Test
public void maxInboundSize_exact() {
StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
.addResponseParameters(ResponseParameters.newBuilder().setSize(1))
@@ -1112,7 +1117,7 @@ public abstract class AbstractInteropTest {
stub.streamingOutputCall(request).next();
}
- @Test(timeout = 10000)
+ @Test
public void maxInboundSize_tooBig() {
StreamingOutputCallRequest request = StreamingOutputCallRequest.newBuilder()
.addResponseParameters(ResponseParameters.newBuilder().setSize(1))
@@ -1132,7 +1137,7 @@ public abstract class AbstractInteropTest {
}
}
- @Test(timeout = 10000)
+ @Test
public void maxOutboundSize_exact() {
// warm up the channel and JVM
blockingStub.emptyCall(Empty.getDefaultInstance());
@@ -1147,7 +1152,7 @@ public abstract class AbstractInteropTest {
stub.streamingOutputCall(request).next();
}
- @Test(timeout = 10000)
+ @Test
public void maxOutboundSize_tooBig() {
// warm up the channel and JVM
blockingStub.emptyCall(Empty.getDefaultInstance());
@@ -1172,7 +1177,7 @@ public abstract class AbstractInteropTest {
return 10485760;
}
- @Test(timeout = 10000)
+ @Test
public void gracefulShutdown() throws Exception {
final List requests = Arrays.asList(
StreamingOutputCallRequest.newBuilder()
@@ -1252,7 +1257,7 @@ public abstract class AbstractInteropTest {
assertFalse(errorSeen.isDone());
}
- @Test(timeout = 10000)
+ @Test
public void customMetadata() throws Exception {
final int responseSize = 314159;
final int requestSize = 271828;
@@ -1331,7 +1336,7 @@ public abstract class AbstractInteropTest {
}
}
- @Test(timeout = 10000)
+ @Test
public void statusCodeAndMessage() throws Exception {
int errorCode = 2;
String errorMessage = "test status message";
@@ -1378,7 +1383,7 @@ public abstract class AbstractInteropTest {
}
/** Sends an rpc to an unimplemented method within TestService. */
- @Test(timeout = 10000)
+ @Test
public void unimplementedMethod() {
try {
blockingStub.unimplementedCall(Empty.getDefaultInstance());
@@ -1394,7 +1399,7 @@ public abstract class AbstractInteropTest {
}
/** Sends an rpc to an unimplemented service on the server. */
- @Test(timeout = 10000)
+ @Test
public void unimplementedService() {
UnimplementedServiceGrpc.UnimplementedServiceBlockingStub stub =
UnimplementedServiceGrpc.newBlockingStub(channel).withInterceptors(tracerSetupInterceptor);
@@ -1413,7 +1418,7 @@ public abstract class AbstractInteropTest {
/** Start a fullDuplexCall which the server will not respond, and verify the deadline expires. */
@SuppressWarnings("MissingFail")
- @Test(timeout = 10000)
+ @Test
public void timeoutOnSleepingServer() throws Exception {
TestServiceGrpc.TestServiceStub stub =
asyncStub.withDeadlineAfter(1, TimeUnit.MILLISECONDS);
diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/ConcurrencyTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/ConcurrencyTest.java
index 638e33bb70..39fc2ba5f1 100644
--- a/interop-testing/src/test/java/io/grpc/testing/integration/ConcurrencyTest.java
+++ b/interop-testing/src/test/java/io/grpc/testing/integration/ConcurrencyTest.java
@@ -44,7 +44,9 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -59,6 +61,9 @@ import org.junit.runners.JUnit4;
// bidirectional streaming requests also.
@RunWith(JUnit4.class)
public class ConcurrencyTest {
+
+ @Rule public final Timeout globalTimeout = Timeout.seconds(10);
+
/**
* A response observer that signals a {@code CountDownLatch} when the proper number of responses
* arrives and the server signals that the RPC is complete.
@@ -165,7 +170,7 @@ public class ConcurrencyTest {
/**
* Tests that gRPC can handle concurrent server-streaming RPCs.
*/
- @Test(timeout = 10000)
+ @Test
public void serverStreamingTest() throws Exception {
CyclicBarrier startBarrier = new CyclicBarrier(NUM_CONCURRENT_REQUESTS);
CountDownLatch responsesDoneSignal = new CountDownLatch(NUM_CONCURRENT_REQUESTS);
diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java
index 07542e91e8..eeb406173d 100644
--- a/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java
+++ b/interop-testing/src/test/java/io/grpc/testing/integration/Http2NettyTest.java
@@ -82,12 +82,12 @@ public class Http2NettyTest extends AbstractInteropTest {
}
}
- @Test(timeout = 10000)
+ @Test
public void remoteAddr() {
assertRemoteAddr("/0:0:0:0:0:0:0:1");
}
- @Test(timeout = 10000)
+ @Test
public void tlsInfo() {
assertX500SubjectDn("CN=testclient, O=Internet Widgits Pty Ltd, ST=Some-State, C=AU");
}
diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java
index a6c0c67fb5..68082f4c5a 100644
--- a/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java
+++ b/interop-testing/src/test/java/io/grpc/testing/integration/Http2OkHttpTest.java
@@ -116,7 +116,7 @@ public class Http2OkHttpTest extends AbstractInteropTest {
return builder;
}
- @Test(timeout = 10000)
+ @Test
public void receivedDataForFinishedStream() throws Exception {
Messages.ResponseParameters.Builder responseParameters =
Messages.ResponseParameters.newBuilder()
@@ -141,7 +141,7 @@ public class Http2OkHttpTest extends AbstractInteropTest {
assertEquals(EMPTY, blockingStub.emptyCall(EMPTY));
}
- @Test(timeout = 10000)
+ @Test
public void wrongHostNameFailHostnameVerification() throws Exception {
ManagedChannel channel = createChannelBuilder()
.overrideAuthority(GrpcUtil.authorityFromHostAndPort(
@@ -161,7 +161,7 @@ public class Http2OkHttpTest extends AbstractInteropTest {
channel.shutdown();
}
- @Test(timeout = 10000)
+ @Test
public void hostnameVerifierWithBadHostname() throws Exception {
ManagedChannel channel = createChannelBuilder()
.overrideAuthority(GrpcUtil.authorityFromHostAndPort(
@@ -181,7 +181,7 @@ public class Http2OkHttpTest extends AbstractInteropTest {
channel.shutdown();
}
- @Test(timeout = 10000)
+ @Test
public void hostnameVerifierWithCorrectHostname() throws Exception {
ManagedChannel channel = createChannelBuilder()
.overrideAuthority(GrpcUtil.authorityFromHostAndPort(
diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/MoreInProcessTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/MoreInProcessTest.java
index b9506e28f3..26f3c88875 100644
--- a/interop-testing/src/test/java/io/grpc/testing/integration/MoreInProcessTest.java
+++ b/interop-testing/src/test/java/io/grpc/testing/integration/MoreInProcessTest.java
@@ -51,7 +51,7 @@ public class MoreInProcessTest {
private static final String UNIQUE_SERVER_NAME =
"in-process server for " + MoreInProcessTest.class;
@Rule
- public final Timeout globalTimeout = new Timeout(1000);
+ public final Timeout globalTimeout = new Timeout(1, TimeUnit.SECONDS);
// use a mutable service registry for later registering the service impl for each test case.
private final MutableHandlerRegistry serviceRegistry = new MutableHandlerRegistry();
private final Server inProcessServer = InProcessServerBuilder.forName(UNIQUE_SERVER_NAME)
diff --git a/interop-testing/src/test/java/io/grpc/testing/integration/StressTestClientTest.java b/interop-testing/src/test/java/io/grpc/testing/integration/StressTestClientTest.java
index 6665073d61..54abe97d83 100644
--- a/interop-testing/src/test/java/io/grpc/testing/integration/StressTestClientTest.java
+++ b/interop-testing/src/test/java/io/grpc/testing/integration/StressTestClientTest.java
@@ -33,7 +33,9 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -41,6 +43,9 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class StressTestClientTest {
+ @Rule
+ public final Timeout globalTimeout = Timeout.seconds(5);
+
@Test
public void ipv6AddressesShouldBeSupported() {
StressTestClient client = new StressTestClient();
@@ -108,7 +113,7 @@ public class StressTestClientTest {
assertEquals("foo.test.google.fr", client.addresses().get(0).getHostName());
}
- @Test(timeout = 5000)
+ @Test
public void gaugesShouldBeExported() throws Exception {
TestServiceServer server = new TestServiceServer();
diff --git a/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java b/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java
index 98a0f73920..5ae27bd646 100644
--- a/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java
+++ b/netty/src/test/java/io/grpc/netty/NettyServerHandlerTest.java
@@ -87,7 +87,9 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentCaptor;
@@ -103,6 +105,9 @@ import org.mockito.stubbing.Answer;
@RunWith(JUnit4.class)
public class NettyServerHandlerTest extends NettyHandlerTestBase {
+ @Rule
+ public final Timeout globalTimeout = Timeout.seconds(1);
+
private static final int STREAM_ID = 3;
@Mock
@@ -529,7 +534,7 @@ public class NettyServerHandlerTest extends NettyHandlerTestBase