summaryrefslogtreecommitdiffstats
path: root/luni/src/test/java
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2015-04-23 23:15:43 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-04-23 23:15:43 +0000
commit99c2aa4c5ea183d615187d6db457adc32a205697 (patch)
tree71a8ca7059ce3b8759ca8e99ac295053fbb490ea /luni/src/test/java
parentf0bed5bdac27e52228aca563d701d9ef47976f01 (diff)
parentb2b83acf152d37d3449feac881bde01c0b92e695 (diff)
downloadlibcore-99c2aa4c5ea183d615187d6db457adc32a205697.zip
libcore-99c2aa4c5ea183d615187d6db457adc32a205697.tar.gz
libcore-99c2aa4c5ea183d615187d6db457adc32a205697.tar.bz2
am b2b83acf: am f8975208: Merge "Test that confirms a socket can be closed during connect()"
* commit 'b2b83acf152d37d3449feac881bde01c0b92e695': Test that confirms a socket can be closed during connect()
Diffstat (limited to 'luni/src/test/java')
-rw-r--r--luni/src/test/java/libcore/java/net/SocketTest.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/luni/src/test/java/libcore/java/net/SocketTest.java b/luni/src/test/java/libcore/java/net/SocketTest.java
index fb09be0..9765a45 100644
--- a/luni/src/test/java/libcore/java/net/SocketTest.java
+++ b/luni/src/test/java/libcore/java/net/SocketTest.java
@@ -31,9 +31,11 @@ import java.net.SocketImpl;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
public class SocketTest extends junit.framework.TestCase {
// See http://b/2980559.
@@ -353,6 +355,37 @@ public class SocketTest extends junit.framework.TestCase {
assertEquals(boundAddress.getPort(), localAddressAfterClose.getPort());
}
+ public void testCloseDuringConnect() throws Exception {
+ final CountDownLatch signal = new CountDownLatch(1);
+
+ final Socket s = new Socket();
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ // This address is reserved for documentation: should never be reachable.
+ InetSocketAddress unreachableIp = new InetSocketAddress("192.0.2.0", 80);
+ // This should never return.
+ s.connect(unreachableIp, 0 /* infinite */);
+ fail("Connect returned unexpectedly for: " + unreachableIp);
+ } catch (SocketException expected) {
+ assertTrue(expected.getMessage().contains("Socket closed"));
+ signal.countDown();
+ } catch (IOException e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+ }.start();
+
+ // Wait for the connect() thread to run and start connect()
+ Thread.sleep(2000);
+
+ s.close();
+
+ boolean connectUnblocked = signal.await(2000, TimeUnit.MILLISECONDS);
+ assertTrue(connectUnblocked);
+ }
+
static class MockServer {
private ExecutorService executor;
private ServerSocket serverSocket;