changeset 51894:6ed2290ba410

8207833: java/nio/channels/Selector/SelectWithConsumer.java testCancel() fails intermittently Reviewed-by: alanb
author mli
date Fri, 20 Jul 2018 15:24:42 +0800
parents e750c1a054fa
children a138b5fe288d
files test/jdk/java/nio/channels/Selector/SelectWithConsumer.java
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/java/nio/channels/Selector/SelectWithConsumer.java	Thu Jul 19 18:21:24 2018 -0700
+++ b/test/jdk/java/nio/channels/Selector/SelectWithConsumer.java	Fri Jul 20 15:24:42 2018 +0800
@@ -548,12 +548,18 @@
             // write to sink to ensure that the source is readable
             sink.write(messageBuffer());
 
+            source.configureBlocking(false);
+            SelectionKey key1 = source.register(sel, SelectionKey.OP_READ);
+            // make sure pipe source is readable before we do following checks.
+            // this is sometime necessary on windows where pipe is implemented
+            // as a pair of connected socket, so there is no guarantee that written
+            // bytes on sink side is immediately available on source side.
+            sel.select();
+
             sink.configureBlocking(false);
-            source.configureBlocking(false);
-            SelectionKey key1 = sink.register(sel, SelectionKey.OP_WRITE);
-            SelectionKey key2 = source.register(sel, SelectionKey.OP_READ);
+            SelectionKey key2 = sink.register(sel, SelectionKey.OP_WRITE);
+            sel.selectNow();
 
-            sel.selectNow();
             assertTrue(sel.keys().contains(key1));
             assertTrue(sel.keys().contains(key2));
             assertTrue(sel.selectedKeys().contains(key1));