Tests - fix for threading issue involving weakly consistent cache

This commit is contained in:
dragonmacher 2019-06-11 10:46:46 -04:00
parent 6de4092875
commit 4919d6ec54
2 changed files with 36 additions and 10 deletions

View file

@ -393,6 +393,20 @@ public abstract class AbstractGTest {
waitForCondition(condition, true /*failOnTimeout*/, failureMessage);
}
/**
* Waits for the given condition to return true
*
* @param condition the condition that returns true when satisfied
* @param failureMessageSupplier the function that will supply the failure message in the
* event of a timeout.
* @throws AssertionFailedError if the condition is not met within the timeout period
*/
public static void waitForCondition(BooleanSupplier condition,
Supplier<String> failureMessageSupplier) throws AssertionFailedError {
waitForCondition(condition, true /*failOnTimeout*/, failureMessageSupplier);
}
/**
* Waits for the given condition to return true. Most of the <code>waitForCondition()</code>
* methods throw an {@link AssertionFailedError} if the timeout period expires.
@ -403,12 +417,18 @@ public abstract class AbstractGTest {
* @param supplier the supplier that returns true when satisfied
*/
public static void waitForConditionWithoutFailing(BooleanSupplier supplier) {
waitForCondition(supplier, false /*failOnTimeout*/, null /*failure message*/);
waitForCondition(supplier, false /*failOnTimeout*/, () -> null /*failure message*/);
}
private static void waitForCondition(BooleanSupplier condition, boolean failOnTimeout,
String failureMessage) throws AssertionFailedError {
waitForCondition(condition, failOnTimeout, () -> failureMessage);
}
private static void waitForCondition(BooleanSupplier condition, boolean failOnTimeout,
Supplier<String> failureMessageSupplier) throws AssertionFailedError {
int totalTime = 0;
while (totalTime <= DEFAULT_WAIT_TIMEOUT) {
@ -423,8 +443,12 @@ public abstract class AbstractGTest {
return;
}
String error = failureMessage != null ? failureMessage : "Timed-out waiting for condition";
throw new AssertionFailedError(error);
String failureMessage = "Timed-out waiting for condition";
if (failureMessageSupplier != null) {
failureMessage = failureMessageSupplier.get();
}
throw new AssertionFailedError(failureMessage);
}
/**