mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-28 15:56:49 +00:00
Improving tests to fix testBindNormalWidget_withoutConfig, and beyond
1. Make waitXXX methods fail if the condition diesn’t turn true. 2. Waiting for loading to complete in tearDown instead of reloading the model 3. Avoiding waiting for load-complete where loading didn’t start 4. Disabling last test in AddConfigWidgetTest 5. Waiting for loading to complete inside setupAndVerifyContents(), not outside 6. Unifying how we wait for loader to complete 7. Adding more logging Bug: 117332845 Test: running all Nexus tests Change-Id: I3070e1ac2b9161179cc3e0800b0cd8162807389a
This commit is contained in:
@@ -2,6 +2,8 @@ package com.android.launcher3.util;
|
||||
|
||||
import android.os.SystemClock;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* A utility class for waiting for a condition to be true.
|
||||
*/
|
||||
@@ -9,16 +11,16 @@ public class Wait {
|
||||
|
||||
private static final long DEFAULT_SLEEP_MS = 200;
|
||||
|
||||
public static boolean atMost(Condition condition, long timeout) {
|
||||
return atMost(condition, timeout, DEFAULT_SLEEP_MS);
|
||||
public static void atMost(String message, Condition condition, long timeout) {
|
||||
atMost(message, condition, timeout, DEFAULT_SLEEP_MS);
|
||||
}
|
||||
|
||||
public static boolean atMost(Condition condition, long timeout, long sleepMillis) {
|
||||
public static void atMost(String message, Condition condition, long timeout, long sleepMillis) {
|
||||
long endTime = SystemClock.uptimeMillis() + timeout;
|
||||
while (SystemClock.uptimeMillis() < endTime) {
|
||||
try {
|
||||
if (condition.isTrue()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
// Ignore
|
||||
@@ -29,11 +31,11 @@ public class Wait {
|
||||
// Check once more before returning false.
|
||||
try {
|
||||
if (condition.isTrue()) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
// Ignore
|
||||
}
|
||||
return false;
|
||||
Assert.fail(message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user