From c88229fd8f58b24b235e889a6b59c8fd6992df3c Mon Sep 17 00:00:00 2001 From: Aurora Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Sun, 28 Aug 2022 08:37:53 +0300 Subject: [PATCH] Fix flaky singlePingIsStored test due to random 0 going out of ping data bounds --- .../plan/storage/database/queries/PingQueriesTest.java | 7 ++++--- Plan/common/src/test/java/utilities/RandomData.java | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/PingQueriesTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/PingQueriesTest.java index 8ccb032fc..21df9b0ec 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/PingQueriesTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/queries/PingQueriesTest.java @@ -31,6 +31,7 @@ import utilities.RandomData; import utilities.TestConstants; import java.util.*; +import java.util.concurrent.ExecutionException; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -71,14 +72,14 @@ public interface PingQueriesTest extends DatabaseTestPreparer { } @Test - default void singlePingIsStored() { + default void singlePingIsStored() throws ExecutionException, InterruptedException { prepareForPingStorage(); - DateObj saved = RandomData.randomIntDateObject(); + DateObj saved = RandomData.randomIntDateObject(1, 4001); // accepted ping range 1-4000 ms int value = saved.getValue(); db().executeTransaction(new PingStoreTransaction(playerUUID, serverUUID(), Collections.singletonList(saved) - )); + )).get(); Map> expected = Collections.singletonMap(playerUUID, Collections.singletonList( new Ping(saved.getDate(), serverUUID(), value, value, value) )); diff --git a/Plan/common/src/test/java/utilities/RandomData.java b/Plan/common/src/test/java/utilities/RandomData.java index d7847926b..83351dfce 100644 --- a/Plan/common/src/test/java/utilities/RandomData.java +++ b/Plan/common/src/test/java/utilities/RandomData.java @@ -201,6 +201,10 @@ public class RandomData { return new DateObj<>(randomTime(), randomInt(0, 500)); } + public static DateObj randomIntDateObject(int rangeStart, int rangeEnd) { + return new DateObj<>(randomTime(), randomInt(rangeStart, rangeEnd)); + } + public static double randomDouble() { return ThreadLocalRandom.current().nextDouble(); }