RFR 8235475: Add additional timestamp to test java/nio/channels/Selector/SelectWithConsumer.java

Michael McMahon michael.x.mcmahon at oracle.com
Fri Dec 6 11:56:25 UTC 2019


On 06/12/2019 11:27, Alan Bateman wrote:
> On 06/12/2019 11:13, Michael McMahon wrote:
>> Hi,
>>
>> Could I get the following small instrumentation change to a test, 
>> reviewed please?
>>
>> It just adds some additional logging for the case when the test fails.
> The existing assert prints a message like this when it fails:
>
> java.lang.AssertionError: select took 1813 ms expected [true] but 
> found [false]
>
> so probably better to expand the existing message so that the crumbs 
> aren't split between the assert and a trace message sent to System.out.
>
> I suspect we will need to change this test to use System.nanoTimes, 
> maybe for another issue.
>
> -Alan
>

Ok, thanks! I'll push patch below. It's likely only a temporary change 
anyhow.

I changed to use nanoTime in this test only, which should guarantee the 
highest millisecond resolution

- Michael.

diff -r 4938269b8b17 
test/jdk/java/nio/channels/Selector/SelectWithConsumer.java
--- a/test/jdk/java/nio/channels/Selector/SelectWithConsumer.java Fri 
Dec 06 10:00:16 2019 +0100
+++ b/test/jdk/java/nio/channels/Selector/SelectWithConsumer.java Fri 
Dec 06 11:52:28 2019 +0000
@@ -454,13 +454,17 @@

          // select(Consumer, timeout)
          try (Selector sel = Selector.open()) {
+            long pre = System.nanoTime();
              scheduleClose(sel, 3, SECONDS);
-            long start = System.currentTimeMillis();
+            long start = System.nanoTime();
              int n = sel.select(k -> assertTrue(false), 60*1000);
-            long duration = System.currentTimeMillis() - start;
+            long after = System.nanoTime();
+            long duration = (after - start) / 1000000;
+            long scheduleDuration = (start - pre) / 1000000;
              assertTrue(n == 0);
              assertTrue(duration > 2000 && duration < 10*1000,
-                    "select took " + duration + " ms");
+                    "select took " + duration + " ms schedule took " +
+                    scheduleDuration + " ms");
              assertFalse(sel.isOpen());
          }
      }


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20191206/822f87bf/attachment.html>


More information about the nio-dev mailing list