Commit 607c5a62 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Fix some flake sources in Chrome Test infra

Split off of
https://chromium-review.googlesource.com/c/chromium/src/+/2442359 as
these fixes will be useful even when that CL gets inevitably reverted :)

Espresso wraps and re-throws Exceptions, so we catch Exceptions whose
cause is a CriteriaNotSatisfiedException as well so that the polling
actually works when using Espresso to check Criteria.

Bug: 1134178
Change-Id: I7c9cdb7e637b306b0c6cb9ecb42a237d99091cb8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2491117Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821013}
parent e1013ca1
...@@ -175,7 +175,7 @@ public class ApplicationTestUtils { ...@@ -175,7 +175,7 @@ public class ApplicationTestUtils {
*/ */
public static void assertWaitForPageScaleFactorMatch( public static void assertWaitForPageScaleFactorMatch(
final ChromeActivity activity, final float expectedScale) { final ChromeActivity activity, final float expectedScale) {
CriteriaHelper.pollInstrumentationThread(() -> { CriteriaHelper.pollUiThread(() -> {
Tab tab = activity.getActivityTab(); Tab tab = activity.getActivityTab();
Criteria.checkThat(tab, Matchers.notNullValue()); Criteria.checkThat(tab, Matchers.notNullValue());
......
...@@ -88,12 +88,19 @@ public class CriteriaHelper { ...@@ -88,12 +88,19 @@ public class CriteriaHelper {
private static void pollThreadInternal( private static void pollThreadInternal(
Runnable criteria, long maxTimeoutMs, long checkIntervalMs, boolean shouldNest) { Runnable criteria, long maxTimeoutMs, long checkIntervalMs, boolean shouldNest) {
CriteriaNotSatisfiedException throwable; Throwable throwable;
try { try {
criteria.run(); criteria.run();
return; return;
} catch (CriteriaNotSatisfiedException cnse) { } catch (Throwable e) {
throwable = cnse; // Espresso catches, wraps, and re-throws the exception we want the CriteriaHelper
// to catch.
if (e instanceof CriteriaNotSatisfiedException
|| e.getCause() instanceof CriteriaNotSatisfiedException) {
throwable = e;
} else {
throw e;
}
} }
TimeoutTimer timer = new TimeoutTimer(maxTimeoutMs); TimeoutTimer timer = new TimeoutTimer(maxTimeoutMs);
while (!timer.isTimedOut()) { while (!timer.isTimedOut()) {
...@@ -105,8 +112,13 @@ public class CriteriaHelper { ...@@ -105,8 +112,13 @@ public class CriteriaHelper {
try { try {
criteria.run(); criteria.run();
return; return;
} catch (CriteriaNotSatisfiedException cnse) { } catch (Throwable e) {
throwable = cnse; if (e instanceof CriteriaNotSatisfiedException
|| e.getCause() instanceof CriteriaNotSatisfiedException) {
throwable = e;
} else {
throw e;
}
} }
} }
throw new AssertionError(throwable); throw new AssertionError(throwable);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment