8208780: (se) test SelectWithConsumer.testReadableAndWriteable(): failure
authoralanb
Fri, 14 Sep 2018 16:56:09 +0100
changeset 51745 90c1dcdebc64
parent 51744 1cb25b6589e9
child 51746 07ae9da7a230
8208780: (se) test SelectWithConsumer.testReadableAndWriteable(): failure Reviewed-by: bpb
test/jdk/java/nio/channels/Selector/SelectWithConsumer.java
--- 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);