changeset 52531:90c1dcdebc64

8208780: (se) test SelectWithConsumer.testReadableAndWriteable(): failure Reviewed-by: bpb
author alanb
date Fri, 14 Sep 2018 16:56:09 +0100
parents 1cb25b6589e9
children 07ae9da7a230
files test/jdk/java/nio/channels/Selector/SelectWithConsumer.java
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/java/nio/channels/Selector/SelectWithConsumer.java	Fri Sep 14 14:44:11 2018 +0200
+++ b/test/jdk/java/nio/channels/Selector/SelectWithConsumer.java	Fri Sep 14 16:56:09 2018 +0100
@@ -22,7 +22,7 @@
  */
 
 /* @test
- * @bug 8199433
+ * @bug 8199433 8208780
  * @run testng SelectWithConsumer
  * @summary Unit test for Selector select(Consumer), select(Consumer,long) and
  *          selectNow(Consumer)
@@ -62,9 +62,19 @@
         var interestOps = key.interestOps();
         var notifiedOps = new AtomicInteger();
 
+        if (expectedOps == 0) {
+            // ensure select(Consumer) does not block indefinitely
+            sel.wakeup();
+        } else {
+            // ensure that the channel is ready for all expected operations
+            sel.select();
+            while ((key.readyOps() & interestOps) != expectedOps) {
+                Thread.sleep(100);
+                sel.select();
+            }
+        }
+
         // select(Consumer)
-        if (expectedOps == 0)
-            sel.wakeup(); // ensure select does not block
         notifiedOps.set(0);
         int n = sel.select(k -> {
             assertTrue(Thread.currentThread() == callerThread);