diff options
author | Kenny Root <kroot@google.com> | 2014-02-25 15:20:33 -0800 |
---|---|---|
committer | Kenny Root <kroot@google.com> | 2014-02-25 15:48:41 -0800 |
commit | 6ced3e6c746117d4145515a11762cff3de3c1fa9 (patch) | |
tree | b7b4dbb212b7fa14002e41e544b6ea5a9aa0ba81 /luni | |
parent | a2e312d89316a8b8cbdafd6a529b30e02fd6f629 (diff) | |
download | libcore-6ced3e6c746117d4145515a11762cff3de3c1fa9.zip libcore-6ced3e6c746117d4145515a11762cff3de3c1fa9.tar.gz libcore-6ced3e6c746117d4145515a11762cff3de3c1fa9.tar.bz2 |
SSLSocketTest: interrupt_read is too flaky
The interrupt test is very flaky currently, because there isn't a good
way to know when the thread we're waiting for is blocked in read. Try to
inspect the stack trace to see if one of the methods is "read" as an
attempt to make it less flaky.
Change-Id: I8503d645ffd5793f6e2fdc20692fbbb4d94cc37c
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java index eb6a98c..fa101f0 100644 --- a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java +++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java @@ -37,6 +37,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import javax.net.ServerSocketFactory; import javax.net.ssl.HandshakeCompletedEvent; @@ -1243,7 +1244,7 @@ public class SSLSocketTest extends TestCase { /** * b/7014266 Test to confirm that an SSLSocket.close() on one - * thread will interupt another thread blocked reading on the same + * thread will interrupt another thread blocked reading on the same * socket. */ public void test_SSLSocket_interrupt_read() throws Exception { @@ -1254,7 +1255,16 @@ public class SSLSocketTest extends TestCase { c.host.getHostName(), c.port, false); - ExecutorService executor = Executors.newSingleThreadExecutor(); + + // Create our own thread group so we can inspect the stack state later. + final ThreadGroup clientGroup = new ThreadGroup("client"); + ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + return new Thread(clientGroup, r); + } + }); + Future<Void> clientFuture = executor.submit(new Callable<Void>() { @Override public Void call() throws Exception { try { @@ -1272,6 +1282,26 @@ public class SSLSocketTest extends TestCase { SSLSocket server = (SSLSocket) c.serverSocket.accept(); server.startHandshake(); + + /* + * Wait for the client to at least be in the "read" method before + * calling close() + */ + Thread[] threads = new Thread[1]; + clientGroup.enumerate(threads); + if (threads[0] != null) { + boolean clientInRead = false; + while (!clientInRead) { + StackTraceElement[] elements = threads[0].getStackTrace(); + for (StackTraceElement element : elements) { + if ("read".equals(element.getMethodName())) { + clientInRead = true; + break; + } + } + } + } + wrapping.close(); clientFuture.get(); server.close(); |