Adding debug tracing for Device.wait

I suspect it may wait for a period of time less than
the specified one, causing flakes.

Test: presubmit
Bug: 177318681
Change-Id: I0be8790c6ee9a5831767fe83c36054ed5a84f8d7
This commit is contained in:
vadimt 2021-01-15 13:58:03 -08:00
parent 4318289207
commit ed86cb19bc
5 changed files with 20 additions and 8 deletions

View File

@ -213,7 +213,7 @@ public class FallbackRecentsTest {
OverviewTask task = overview.getCurrentTask();
assertNotNull("overview.getCurrentTask() returned null (1)", task);
assertNotNull("OverviewTask.open returned null", task.open());
assertTrue("Test activity didn't open from Overview", mDevice.wait(Until.hasObject(
assertTrue("Test activity didn't open from Overview", TestHelpers.wait(Until.hasObject(
By.pkg(getAppPackageName()).text("TestActivity2")),
DEFAULT_UI_TIMEOUT));
@ -230,7 +230,7 @@ public class FallbackRecentsTest {
// Test dismissing all tasks.
pressHomeAndGoToOverview().dismissAllTasks();
assertTrue("Fallback Launcher not visible", mDevice.wait(Until.hasObject(By.pkg(
assertTrue("Fallback Launcher not visible", TestHelpers.wait(Until.hasObject(By.pkg(
mOtherLauncherActivity.packageName)), WAIT_TIME_MS));
}

View File

@ -237,7 +237,7 @@ public abstract class AbstractLauncherUiTest {
@Before
public void setUp() throws Exception {
Assert.assertTrue("Keyguard is visible",
mDevice.wait(
TestHelpers.wait(
Until.gone(By.res(SYSTEMUI_PACKAGE, "keyguard_status_view")), 60000));
final String launcherPackageName = mDevice.getLauncherPackageName();
@ -470,8 +470,7 @@ public abstract class AbstractLauncherUiTest {
}
getInstrumentation().getTargetContext().startActivity(intent);
assertTrue("App didn't start: " + selector,
UiDevice.getInstance(getInstrumentation())
.wait(Until.hasObject(selector), DEFAULT_UI_TIMEOUT));
TestHelpers.wait(Until.hasObject(selector), DEFAULT_UI_TIMEOUT));
}
public static ActivityInfo resolveSystemAppInfo(String category) {

View File

@ -68,8 +68,7 @@ abstract class Launchable {
mLauncher.assertTrue(
"App didn't start: " + label,
mLauncher.getDevice().wait(Until.hasObject(selector),
LauncherInstrumentation.WAIT_TIME_MS));
TestHelpers.wait(Until.hasObject(selector), LauncherInstrumentation.WAIT_TIME_MS));
return new Background(mLauncher);
}

View File

@ -933,7 +933,7 @@ public final class LauncherInstrumentation {
@NonNull
UiObject2 waitForAndroidObject(String resId) {
final UiObject2 object = mDevice.wait(
final UiObject2 object = TestHelpers.wait(
Until.findObject(By.res(ANDROID_PACKAGE, resId)), WAIT_TIME_MS);
assertNotNull("Can't find a android object with id: " + resId, object);
return object;

View File

@ -27,6 +27,11 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.os.DropBoxManager;
import android.os.SystemClock;
import android.util.Log;
import androidx.test.uiautomator.SearchCondition;
import androidx.test.uiautomator.UiDevice;
import org.junit.Assert;
@ -35,6 +40,7 @@ import java.util.List;
public class TestHelpers {
private static final String TAG = "Tapl";
private static Boolean sIsInLauncherProcess;
public static boolean isInLauncherProcess() {
@ -154,4 +160,12 @@ public class TestHelpers {
return null;
}
}
public static <R> R wait(SearchCondition<R> condition, long timeout) {
Log.d(TAG,
"TestHelpers.wait, condition=" + timeout + ", time=" + SystemClock.uptimeMillis());
final R result = UiDevice.getInstance(getInstrumentation()).wait(condition, timeout);
Log.d(TAG, "TestHelpers.wait, result=" + result + ", time=" + SystemClock.uptimeMillis());
return result;
}
}