Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

Fix bug with Inconsistents time unit conversion #1

Merged
merged 1 commit into from
Apr 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<dependency>
<groupId>org.rnorth.visible-assertions</groupId>
<artifactId>visible-assertions</artifactId>
<version>1.0.3</version>
<version>1.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static <T> T retryUntilConsistent(final int consistentTime, final int tot
long[] bestRun = {0};
Object[] bestRunValue = {null};

long consistentTimeInMillis = timeUnit.convert(consistentTime, TimeUnit.MILLISECONDS);
long consistentTimeInMillis = TimeUnit.MILLISECONDS.convert(consistentTime, timeUnit);

return Unreliables.retryUntilSuccess(totalTimeout, timeUnit, () -> {
T value = lambda.call();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertTrue;
import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;


Expand Down Expand Up @@ -49,4 +50,18 @@ public void testNotConsistentLongEnough() {
assertEquals("An exception is thrown if the result is never consistent", InconsistentResultsException.class, cause.getClass());
}
}

@Test
public void testUnitConversion() {
long start = System.currentTimeMillis();

Inconsistents.retryUntilConsistent(1, 5, TimeUnit.SECONDS, () -> {
Thread.sleep(10L);
// this result won't be consistent until after 1.5s
long now = System.currentTimeMillis();
return (now - start) / 1500;
});

assertTrue("At least one second elapsed", System.currentTimeMillis() - start > 1000);
}
}