Fix flaky singlePingIsStored test due to random 0 going out of ping data bounds

This commit is contained in:
Aurora Lahtela 2022-08-28 08:37:53 +03:00
parent bfe59008d0
commit c88229fd8f
2 changed files with 8 additions and 3 deletions

View File

@ -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<Integer> saved = RandomData.randomIntDateObject();
DateObj<Integer> 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<UUID, List<Ping>> expected = Collections.singletonMap(playerUUID, Collections.singletonList(
new Ping(saved.getDate(), serverUUID(), value, value, value)
));

View File

@ -201,6 +201,10 @@ public class RandomData {
return new DateObj<>(randomTime(), randomInt(0, 500));
}
public static DateObj<Integer> randomIntDateObject(int rangeStart, int rangeEnd) {
return new DateObj<>(randomTime(), randomInt(rangeStart, rangeEnd));
}
public static double randomDouble() {
return ThreadLocalRandom.current().nextDouble();
}