This is an automated email from the ASF dual-hosted git repository.
dlmarion pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push:
new e910adc56c Fixed TimerTest elapsed duration checks (#4788)
e910adc56c is described below
commit e910adc56c88d998c9e4c1c9fa19978e50052f77
Author: Dave Marion <[email protected]>
AuthorDate: Mon Aug 5 14:04:53 2024 -0400
Fixed TimerTest elapsed duration checks (#4788)
Modified the checks of elapsed duration of Thread.sleep calls
such that they are now checking that at the elapsed duration is
at least the number of millis specified in the method parameter
instead of performing an exact check, which could sometimes fail.
---
.../org/apache/accumulo/core/util/TimerTest.java | 24 +++++++---------------
1 file changed, 7 insertions(+), 17 deletions(-)
diff --git a/core/src/test/java/org/apache/accumulo/core/util/TimerTest.java
b/core/src/test/java/org/apache/accumulo/core/util/TimerTest.java
index b090214126..67b40d07e3 100644
--- a/core/src/test/java/org/apache/accumulo/core/util/TimerTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/util/TimerTest.java
@@ -65,8 +65,6 @@ public class TimerTest {
assertTrue(timer.hasElapsed(Duration.ofMillis(50)),
"The timer should indicate that 50 milliseconds have elapsed.");
- assertFalse(timer.hasElapsed(Duration.ofMillis(100)),
- "The timer should not indicate that 100 milliseconds have elapsed.");
}
@Test
@@ -77,33 +75,25 @@ public class TimerTest {
assertTrue(timer.hasElapsed(50, MILLISECONDS),
"The timer should indicate that 50 milliseconds have elapsed.");
- assertFalse(timer.hasElapsed(100, MILLISECONDS),
- "The timer should not indicate that 100 milliseconds have elapsed.");
}
@Test
- public void testElapsedPrecision() throws InterruptedException {
+ public void testElapsedWithTimeUnit() throws InterruptedException {
Timer timer = Timer.startNew();
final int sleepMillis = 50;
Thread.sleep(sleepMillis);
long elapsedMillis = timer.elapsed(MILLISECONDS);
- assertEquals(sleepMillis, elapsedMillis, 5, "Elapsed time in milliseconds
is not accurate.");
- }
-
- @Test
- public void testElapsedWithTimeUnit() throws InterruptedException {
- Timer timer = Timer.startNew();
- Thread.sleep(50);
+ assertTrue(elapsedMillis >= sleepMillis, "Elapsed time in milliseconds is
not correct.");
- long elapsedMillis = timer.elapsed(MILLISECONDS);
- assertEquals(50, elapsedMillis, 5, "Elapsed time in milliseconds is not
accurate.");
+ if (elapsedMillis < 1000) {
+ long elapsedSeconds = timer.elapsed(TimeUnit.SECONDS);
+ assertEquals(0, elapsedSeconds,
+ "Elapsed time in seconds should be 0 for 50 milliseconds of sleep.");
+ }
- long elapsedSeconds = timer.elapsed(TimeUnit.SECONDS);
- assertEquals(0, elapsedSeconds,
- "Elapsed time in seconds should be 0 for 50 milliseconds of sleep.");
}
}