Skip to content

Commit

Permalink
Fix timetout unit test running on slow machines
Browse files Browse the repository at this point in the history
  • Loading branch information
msmygit committed Apr 12, 2024
1 parent ac61a81 commit af3928b
Showing 1 changed file with 16 additions and 16 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 nosqlbench
* Copyright (c) 2020-2024 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,11 +26,11 @@ public class TimeoutPredicateTest {

@Test
public void testNeverCompletablePreciate() {
int interval=10;
int timeout=500;
int interval = 10;
int timeout = 500;

TimeoutPredicate<Boolean> wontMakeIt = TimeoutPredicate.of(
()->false,
() -> false,
l -> l,
Duration.ofMillis(timeout),
Duration.ofMillis(interval),
Expand All @@ -43,12 +43,12 @@ public void testNeverCompletablePreciate() {
assertThat(resultNow.status()).isEqualTo(TimeoutPredicate.Status.pending);

resultNow = wontMakeIt.test();
assertThat(resultNow.duration_ns()).isBetween(10*1_000_000L,50*1_000_000L);
assertThat(resultNow.duration_ns()).isBetween(10 * 1_000_000L, 50 * 1_000_000_000L);
assertThat(resultNow.value()).isFalse();
assertThat(resultNow.status()).isEqualTo(TimeoutPredicate.Status.pending);

while (resultNow.status()== TimeoutPredicate.Status.pending) {
resultNow=wontMakeIt.test();
while (resultNow.status() == TimeoutPredicate.Status.pending) {
resultNow = wontMakeIt.test();
}

assertThat(resultNow.status()).isEqualTo(TimeoutPredicate.Status.incomplete);
Expand All @@ -57,10 +57,10 @@ public void testNeverCompletablePreciate() {

@Test
public void testImmediatelyCompletablePreciate() {
int interval=10;
int timeout=5000;
int interval = 10;
int timeout = 5000;
TimeoutPredicate<Boolean> canMakeIt = TimeoutPredicate.of(
()->true,
() -> true,
l -> l,
Duration.ofMillis(timeout),
Duration.ofMillis(interval),
Expand All @@ -77,13 +77,13 @@ public void testImmediatelyCompletablePreciate() {
@Test
public void testEventuallyCompletePredicate() {

int interval=250;
int timeout=5000;
int interval = 250;
int timeout = 5000;
long now = System.currentTimeMillis();
long inASec = now+1000;
long inASec = now + 1000;
TimeoutPredicate<Long> canMakeIt = TimeoutPredicate.of(
System::currentTimeMillis,
l -> l>inASec,
l -> l > inASec,
Duration.ofMillis(timeout),
Duration.ofMillis(interval),
true
Expand All @@ -92,9 +92,9 @@ public void testEventuallyCompletePredicate() {
TimeoutPredicate.Result<Long> result = canMakeIt.test();
System.out.println(result);

while (result.status()== TimeoutPredicate.Status.pending) {
while (result.status() == TimeoutPredicate.Status.pending) {
// canMakeIt.blockUntilNextInterval();
result=canMakeIt.test();
result = canMakeIt.test();
System.out.println(canMakeIt);
System.out.println(result);
}
Expand Down

0 comments on commit af3928b

Please sign in to comment.