From 0853aee3b377cf9f17340a85f600651db42e6999 Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Fri, 25 Oct 2024 15:35:49 +0000 Subject: [PATCH] 8338426: Test java/nio/channels/Selector/WakeupNow.java failed Reviewed-by: jpai, alanb --- .../java/nio/channels/Selector/WakeupNow.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/test/jdk/java/nio/channels/Selector/WakeupNow.java b/test/jdk/java/nio/channels/Selector/WakeupNow.java index 23dc0c30907..a8d1222ba13 100644 --- a/test/jdk/java/nio/channels/Selector/WakeupNow.java +++ b/test/jdk/java/nio/channels/Selector/WakeupNow.java @@ -26,7 +26,9 @@ * @summary Ensure that the wakeup state is cleared by selectNow() */ -import java.nio.channels.*; +import java.nio.channels.Pipe; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; public class WakeupNow { @@ -47,14 +49,15 @@ public class WakeupNow { // ensure wakeup is consumed by selectNow Thread.sleep(2000); sel.selectNow(); - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime(); int n = sel.select(2000); - long endTime = System.currentTimeMillis(); + long endTime = System.nanoTime(); p.source().close(); p.sink().close(); sel.close(); - if (endTime - startTime < 1000) - throw new RuntimeException("test failed"); + long delta = endTime - startTime; + if (delta < 1_000_000_000) + throw new RuntimeException("test failed with delta " + delta); } // Test if selectNow clears wakeup with only the wakeup fd @@ -62,18 +65,17 @@ public class WakeupNow { // This fails before the fix on Solaris private static void test2() throws Exception { Selector sel = Selector.open(); - Pipe p = Pipe.open(); - p.source().configureBlocking(false); sel.wakeup(); // ensure wakeup is consumed by selectNow Thread.sleep(2000); sel.selectNow(); - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime(); int n = sel.select(2000); - long endTime = System.currentTimeMillis(); + long endTime = System.nanoTime(); sel.close(); - if (endTime - startTime < 1000) - throw new RuntimeException("test failed"); + long delta = endTime - startTime; + if (delta < 1_000_000_000) + throw new RuntimeException("test failed with delta " + delta); } }