From dd712993651f9f314aa6cb9a58fbcce90a175868 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sun, 8 Aug 2021 12:07:36 +0700 Subject: [PATCH] Improve flaky test in Ajc1612Tests further By using System.nanoTime() instead of currentTimeMillis(), the flakiness even with the original 10,000 rounds is significantly lower than before. Making my IDE repeat the test until failure, it took on average 150 runs to make it fail. So, the more accurate timing helps. With 100,000 rounds, it was even more stable, but eventually I could make it fail. With 1,000,000 rounds however, even running the test 500x could not make it fail. So for all practical purposes, I think the test is reasonably stable now. Closes #83. Signed-off-by: Alexander Kriegisch --- tests/bugs1612/pr356612/AnnoBinding.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/bugs1612/pr356612/AnnoBinding.java b/tests/bugs1612/pr356612/AnnoBinding.java index fd47c6785..609866fc3 100644 --- a/tests/bugs1612/pr356612/AnnoBinding.java +++ b/tests/bugs1612/pr356612/AnnoBinding.java @@ -10,19 +10,19 @@ import org.aspectj.lang.reflect.FieldSignature; public class AnnoBinding { public static void main(String[] argv) { - long stime = System.currentTimeMillis(); - // 10,000 or 100,000 rounds are too quick, making the test flaky + long stime = System.nanoTime(); + // 10,000 or 100,000 rounds are too quick, making the test flaky on rare occasions final int ROUNDS = 1000 * 1000; for (int i = 0; i < ROUNDS; i++) { runOne(); } - long etime = System.currentTimeMillis(); + long etime = System.nanoTime(); long manual = (etime - stime); - stime = System.currentTimeMillis(); + stime = System.nanoTime(); for (int i = 0; i < ROUNDS; i++) { runTwo(); } - etime = System.currentTimeMillis(); + etime = System.nanoTime(); long woven = (etime - stime); System.out.println("woven=" + woven + " manual=" + manual); if (woven > manual) { -- 2.39.5