From 492b0d716bf1efbb2212ba15960c7010e02c2bf0 Mon Sep 17 00:00:00 2001 From: Till Neunast Date: Sun, 15 Sep 2024 09:19:24 +1200 Subject: [PATCH] Allow for low system timer accuracy --- jpos/src/test/java/org/jpos/space/TSpaceTestCase.java | 4 ++-- .../java/org/jpos/util/ThroughputControlTestCase.java | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/jpos/src/test/java/org/jpos/space/TSpaceTestCase.java b/jpos/src/test/java/org/jpos/space/TSpaceTestCase.java index c51cda0e32..6b71681e77 100644 --- a/jpos/src/test/java/org/jpos/space/TSpaceTestCase.java +++ b/jpos/src/test/java/org/jpos/space/TSpaceTestCase.java @@ -79,7 +79,7 @@ public void testExpiration() { sp.out("testExpiration_Key", "ABC", 50); assertEquals("ABC", sp.rdp("testExpiration_Key")); try { - Thread.sleep(60); + Thread.sleep(75); // allow for low system timer accuracy } catch (InterruptedException e) { } assertNull(sp.rdp("testExpiration_Key"), "ABC"); @@ -136,7 +136,7 @@ public void testGC() throws Exception { sp.out("testGC_Key", "XYZ", 50); assertEquals("ABC", sp.rdp("testGC_Key")); try { - Thread.sleep(60); + Thread.sleep(75); // allow for low system timer accuracy } catch (InterruptedException e) { } assertEquals("testGC_Key", sp.getKeysAsString()); diff --git a/jpos/src/test/java/org/jpos/util/ThroughputControlTestCase.java b/jpos/src/test/java/org/jpos/util/ThroughputControlTestCase.java index 90972e12bf..bd432dd882 100644 --- a/jpos/src/test/java/org/jpos/util/ThroughputControlTestCase.java +++ b/jpos/src/test/java/org/jpos/util/ThroughputControlTestCase.java @@ -32,23 +32,24 @@ public void testSingleThread () throws Exception { ThroughputControl tc = new ThroughputControl (2, 1000); Instant start = Instant.now(); assertTrue (tc.control() == 0L, "Control should return 0L"); + // Allow for low system timer accuracy via a tolerance of 25 milliseconds either way: assertTrue ( - Duration.between(start, Instant.now()).toMillis() < 1000L, + Duration.between(start, Instant.now()).toMillis() < 1000L + 25L, "Elapsed time should be less than one second" ); tc.control(); assertTrue ( - Duration.between(start, Instant.now()).toMillis() < 1000L, + Duration.between(start, Instant.now()).toMillis() < 1000L + 25L, "Elapsed time should still be less than one second" ); tc.control(); assertTrue ( - Duration.between(start, Instant.now()).toMillis() > 1000L, + Duration.between(start, Instant.now()).toMillis() > 1000L - 25L, "Elapsed time should be greater than one second" ); tc.control(); assertTrue ( - Duration.between(start, Instant.now()).toMillis() < 2000L, + Duration.between(start, Instant.now()).toMillis() < 2000L - 25L, "second transaction should be less than two seconds" ); }