Skip to content

Commit 0853aee

Browse files
author
Brian Burkhalter
committed
8338426: Test java/nio/channels/Selector/WakeupNow.java failed
Reviewed-by: jpai, alanb
1 parent c202a2f commit 0853aee

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

test/jdk/java/nio/channels/Selector/WakeupNow.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
* @summary Ensure that the wakeup state is cleared by selectNow()
2727
*/
2828

29-
import java.nio.channels.*;
29+
import java.nio.channels.Pipe;
30+
import java.nio.channels.SelectionKey;
31+
import java.nio.channels.Selector;
3032

3133
public class WakeupNow {
3234

@@ -47,33 +49,33 @@ private static void test1() throws Exception {
4749
// ensure wakeup is consumed by selectNow
4850
Thread.sleep(2000);
4951
sel.selectNow();
50-
long startTime = System.currentTimeMillis();
52+
long startTime = System.nanoTime();
5153
int n = sel.select(2000);
52-
long endTime = System.currentTimeMillis();
54+
long endTime = System.nanoTime();
5355
p.source().close();
5456
p.sink().close();
5557
sel.close();
56-
if (endTime - startTime < 1000)
57-
throw new RuntimeException("test failed");
58+
long delta = endTime - startTime;
59+
if (delta < 1_000_000_000)
60+
throw new RuntimeException("test failed with delta " + delta);
5861
}
5962

6063
// Test if selectNow clears wakeup with only the wakeup fd
6164
// in the selector.
6265
// This fails before the fix on Solaris
6366
private static void test2() throws Exception {
6467
Selector sel = Selector.open();
65-
Pipe p = Pipe.open();
66-
p.source().configureBlocking(false);
6768
sel.wakeup();
6869
// ensure wakeup is consumed by selectNow
6970
Thread.sleep(2000);
7071
sel.selectNow();
71-
long startTime = System.currentTimeMillis();
72+
long startTime = System.nanoTime();
7273
int n = sel.select(2000);
73-
long endTime = System.currentTimeMillis();
74+
long endTime = System.nanoTime();
7475
sel.close();
75-
if (endTime - startTime < 1000)
76-
throw new RuntimeException("test failed");
76+
long delta = endTime - startTime;
77+
if (delta < 1_000_000_000)
78+
throw new RuntimeException("test failed with delta " + delta);
7779
}
7880

7981
}

0 commit comments

Comments
 (0)