From d2ab0cecb823ceed4525d3ab3d917418076bec59 Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Thu, 22 Mar 2018 05:37:32 -0700 Subject: remote/http: properly support read timeout Also, remove unused SO_TIMEOUT. Fixes #4890 cc @benjaminp Closes #4895. PiperOrigin-RevId: 190051030 --- .../remote/blobstore/http/HttpBlobStoreTest.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/test/java/com/google/devtools/build/lib/remote/blobstore') diff --git a/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStoreTest.java b/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStoreTest.java index 7854cb53e7..6850f9e17d 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStoreTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/blobstore/http/HttpBlobStoreTest.java @@ -32,6 +32,7 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler.Sharable; +import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; @@ -49,8 +50,10 @@ import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.HttpVersion; +import io.netty.handler.timeout.ReadTimeoutException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.net.ConnectException; import java.net.URI; import java.util.HashMap; import java.util.List; @@ -82,6 +85,44 @@ public class HttpBlobStoreTest { return ((ServerSocketChannel) sb.bind("localhost", 0).sync().channel()); } + @Test(expected = ConnectException.class, timeout = 30000) + public void timeoutShouldWork_connect() throws Exception { + ServerSocketChannel server = startServer(new ChannelHandlerAdapter() {}); + int serverPort = server.localAddress().getPort(); + closeServerChannel(server); + + Credentials credentials = newCredentials(); + HttpBlobStore blobStore = + new HttpBlobStore(new URI("http://localhost:" + serverPort), 5, credentials); + blobStore.get("key", new ByteArrayOutputStream()); + fail("Exception expected"); + } + + @Test(expected = ReadTimeoutException.class, timeout = 30000) + public void timeoutShouldWork_read() throws Exception { + ServerSocketChannel server = null; + try { + server = + startServer( + new SimpleChannelInboundHandler() { + @Override + protected void channelRead0( + ChannelHandlerContext channelHandlerContext, FullHttpRequest fullHttpRequest) { + // Don't respond and force a client timeout. + } + }); + int serverPort = server.localAddress().getPort(); + + Credentials credentials = newCredentials(); + HttpBlobStore blobStore = + new HttpBlobStore(new URI("http://localhost:" + serverPort), 5, credentials); + blobStore.get("key", new ByteArrayOutputStream()); + fail("Exception expected"); + } finally { + closeServerChannel(server); + } + } + @Test public void expiredAuthTokensShouldBeRetried_get() throws Exception { expiredAuthTokensShouldBeRetried_get(ErrorType.UNAUTHORIZED); -- cgit v1.2.3