summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2012-10-16 17:53:01 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-10-16 17:53:01 -0700
commit1b18a42ce11e536a12a21166b5e7790a73285af4 (patch)
treee1cf2c9af64611c3f4656c8384acea7c1e675a87
parent7434c155a49ebe96d16ae29dbc2dde0b414d4f88 (diff)
parentd2f41fe210bf0fe958345f84e95e8f037c325005 (diff)
downloadlibcore-1b18a42ce11e536a12a21166b5e7790a73285af4.zip
libcore-1b18a42ce11e536a12a21166b5e7790a73285af4.tar.gz
libcore-1b18a42ce11e536a12a21166b5e7790a73285af4.tar.bz2
am d2f41fe2: Merge "Fix ConcurrentCloseTest flakiness."
* commit 'd2f41fe210bf0fe958345f84e95e8f037c325005': Fix ConcurrentCloseTest flakiness.
-rw-r--r--expectations/knownfailures.txt9
-rw-r--r--luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java14
-rw-r--r--luni/src/test/java/libcore/java/net/URLConnectionTest.java2
-rw-r--r--luni/src/test/java/libcore/java/nio/channels/SelectorTest.java3
-rw-r--r--support/src/test/java/tests/net/StuckServer.java60
5 files changed, 44 insertions, 44 deletions
diff --git a/expectations/knownfailures.txt b/expectations/knownfailures.txt
index 61ca999..c8bcde9 100644
--- a/expectations/knownfailures.txt
+++ b/expectations/knownfailures.txt
@@ -185,15 +185,6 @@
bug: 2400429
},
{
- description: "Concurrent close tests fail on the device",
- names: [
- "libcore.java.net.ConcurrentCloseTest#test_connect",
- "libcore.java.net.ConcurrentCloseTest#test_connect_nonBlocking"
- ],
- modes: [ "device" ],
- bug: 3044772
-},
-{
description: "HTTPS connections should not be pooled.",
name: "libcore.java.net.URLConnectionTest#testConnectViaHttpsReusingConnectionsDifferentFactories",
bug: 3042192
diff --git a/luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java b/luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java
index 6988f6f..99a479c2 100644
--- a/luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java
+++ b/luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java
@@ -50,11 +50,11 @@ public class ConcurrentCloseTest extends junit.framework.TestCase {
}
public void test_connect() throws Exception {
- StuckServer ss = new StuckServer();
+ StuckServer ss = new StuckServer(false);
Socket s = new Socket();
new Killer(s).start();
try {
- System.err.println("connect " + s + " to " + ss.getLocalSocketAddress() + "...");
+ System.err.println("connect...");
s.connect(ss.getLocalSocketAddress());
fail("connect returned: " + s + "!");
} catch (SocketException expected) {
@@ -65,11 +65,11 @@ public class ConcurrentCloseTest extends junit.framework.TestCase {
}
public void test_connect_timeout() throws Exception {
- StuckServer ss = new StuckServer();
+ StuckServer ss = new StuckServer(false);
Socket s = new Socket();
new Killer(s).start();
try {
- System.err.println("connect (with timeout) " + s + " to " + ss.getLocalSocketAddress() + "...");
+ System.err.println("connect (with timeout)...");
s.connect(ss.getLocalSocketAddress(), 3600 * 1000);
fail("connect returned: " + s + "!");
} catch (SocketException expected) {
@@ -80,11 +80,11 @@ public class ConcurrentCloseTest extends junit.framework.TestCase {
}
public void test_connect_nonBlocking() throws Exception {
- StuckServer ss = new StuckServer();
+ StuckServer ss = new StuckServer(false);
SocketChannel s = SocketChannel.open();
new Killer(s.socket()).start();
try {
- System.err.println("connect (non-blocking) " + s + " to " + ss.getLocalSocketAddress() + "...");
+ System.err.println("connect (non-blocking)...");
s.configureBlocking(false);
s.connect(ss.getLocalSocketAddress());
while (!s.finishConnect()) {
@@ -238,7 +238,7 @@ public class ConcurrentCloseTest extends junit.framework.TestCase {
try {
System.err.println("sleep...");
Thread.sleep(2000);
- System.err.println("close " + s + "...");
+ System.err.println("close...");
s.getClass().getMethod("close").invoke(s);
} catch (Exception ex) {
ex.printStackTrace();
diff --git a/luni/src/test/java/libcore/java/net/URLConnectionTest.java b/luni/src/test/java/libcore/java/net/URLConnectionTest.java
index e40ba57..1f2ebf9 100644
--- a/luni/src/test/java/libcore/java/net/URLConnectionTest.java
+++ b/luni/src/test/java/libcore/java/net/URLConnectionTest.java
@@ -1645,7 +1645,7 @@ public final class URLConnectionTest extends TestCase {
* addresses. This is typically one IPv4 address and one IPv6 address.
*/
public void testConnectTimeouts() throws IOException {
- StuckServer ss = new StuckServer();
+ StuckServer ss = new StuckServer(false);
int serverPort = ss.getLocalPort();
URLConnection urlConnection = new URL("http://localhost:" + serverPort).openConnection();
int timeout = 1000;
diff --git a/luni/src/test/java/libcore/java/nio/channels/SelectorTest.java b/luni/src/test/java/libcore/java/nio/channels/SelectorTest.java
index f73b6d5..4fc70c4 100644
--- a/luni/src/test/java/libcore/java/nio/channels/SelectorTest.java
+++ b/luni/src/test/java/libcore/java/nio/channels/SelectorTest.java
@@ -55,11 +55,10 @@ public class SelectorTest extends TestCase {
public void testNonBlockingConnect_slow() throws Exception {
// Test the case where we have to wait for the connection.
Selector selector = Selector.open();
- StuckServer ss = new StuckServer();
+ StuckServer ss = new StuckServer(true);
try {
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
- ss.unblockAfterMs(2000);
sc.connect(ss.getLocalSocketAddress());
SelectionKey key = sc.register(selector, SelectionKey.OP_CONNECT);
assertEquals(1, selector.select());
diff --git a/support/src/test/java/tests/net/StuckServer.java b/support/src/test/java/tests/net/StuckServer.java
index eababce..f7a3118 100644
--- a/support/src/test/java/tests/net/StuckServer.java
+++ b/support/src/test/java/tests/net/StuckServer.java
@@ -17,6 +17,7 @@
package tests.net;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
@@ -26,48 +27,57 @@ import java.util.ArrayList;
* A test ServerSocket that you can't connect to --- connects will time out.
*/
public final class StuckServer {
+ private static final boolean DEBUG = false;
+
private ServerSocket serverSocket;
+ private InetSocketAddress address;
private ArrayList<Socket> clients = new ArrayList<Socket>();
- public StuckServer() throws IOException {
+ public StuckServer(boolean useBacklog) throws IOException {
// Set a backlog and use it up so that we can expect the
- // connection to time out. According to Steven's
+ // connection to time out. According to Stevens
// 4.5 "listen function", Linux adds 3 to the specified
// backlog, so we need to connect 4 times before it will hang.
- serverSocket = new ServerSocket(0, 1);
- for (int i = 0; i < 4; i++) {
- clients.add(new Socket(serverSocket.getInetAddress(), serverSocket.getLocalPort()));
- }
- }
-
- public void unblockAfterMs(final int ms) {
- Thread t = new Thread(new Runnable() {
- @Override public void run() {
- try {
- Thread.sleep(ms);
- for (Socket client : clients) {
- client.close();
- }
- clients.clear();
- clients.add(serverSocket.accept());
- } catch (Exception ex) {
- ex.printStackTrace();
+ // The trouble with this is that it won't hang forever.
+ // After 10s or so, the kernel allows a couple more connections.
+ // This mode is ony useful if you actually want to continue eventually; we use it to
+ // test non-blocking connects, for example, where you want to test every part of the code.
+ if (useBacklog) {
+ this.serverSocket = new ServerSocket(0, 1);
+ this.address = (InetSocketAddress) serverSocket.getLocalSocketAddress();
+ if (DEBUG) {
+ System.err.println("StuckServer: " + serverSocket);
+ }
+ for (int i = 0; i < 4; ++i) {
+ Socket client = new Socket(serverSocket.getInetAddress(), serverSocket.getLocalPort());
+ clients.add(client);
+ if (DEBUG) {
+ System.err.println("StuckServer client " + i + " - " + client);
}
}
- });
- t.start();
+ } else {
+ // In general, though, you don't want to rely on listen(2) backlog. http://b/6971145.
+ // RFC 5737 implies this network will be unreachable. (There are two other networks
+ // to try if we have trouble with this one.)
+ // We've had trouble with 10.* in the past (because test labs running CTS often use
+ // net 10!) but hopefully this network will be better.
+ InetAddress testNet1 = InetAddress.getByAddress(new byte[] { (byte) 192, 0, 2, 0 });
+ this.address = new InetSocketAddress(testNet1, 80);
+ }
}
public InetSocketAddress getLocalSocketAddress() {
- return (InetSocketAddress) serverSocket.getLocalSocketAddress();
+ return address;
}
public int getLocalPort() {
- return serverSocket.getLocalPort();
+ return address.getPort();
}
public void close() throws IOException {
- serverSocket.close();
+ if (serverSocket != null) {
+ serverSocket.close();
+ }
for (Socket client : clients) {
client.close();
}