# HG changeset patch # User mli # Date 1532071482 -28800 # Node ID 6ed2290ba410983559e90668e710df6b5d9ce3aa # Parent e750c1a054fab06e6e17acdbf445503f222e6ef2 8207833: java/nio/channels/Selector/SelectWithConsumer.java testCancel() fails intermittently Reviewed-by: alanb diff -r e750c1a054fa -r 6ed2290ba410 test/jdk/java/nio/channels/Selector/SelectWithConsumer.java --- 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));