Skip all tests after a test times out

That test can continue running in the "Time-limited test" thread,
and we don't know whether it makes sense to wait for its completion.

Flag: EXEMPT test fix
Fixes: 405849365
Test: TAPL tests; pre/postsubmit
Change-Id: I3bdd6e5b07f109124f938766b7f2e427d2e39b01
This commit is contained in:
Vadim Tryshev committed 2025-05-15 13:44:40 -07:00
1 parent aa0b9183da
commit 3743ca97c7
4 files changed
+17 -23

No files matched your search

@@ -23,6 +23,7 @@ import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static com.android.launcher3.tapl.LauncherInstrumentation.WAIT_TIME_MS;
import static com.android.launcher3.tapl.TestHelpers.getHomeIntentInPackage;
import static com.android.launcher3.tapl.TestHelpers.getLauncherInMyProcess;
import static com.android.launcher3.ui.TaplTestsLauncher3Test.getAppPackageName;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.rule.ShellCommandRule.disableHeadsUpNotification;
import static com.android.launcher3.util.rule.ShellCommandRule.getLauncherCommand;
@@ -30,7 +31,6 @@ import static com.android.launcher3.util.ui.AbstractLauncherUiTest.DEFAULT_BROAD
import static com.android.launcher3.util.ui.AbstractLauncherUiTest.resolveSystemApp;
import static com.android.launcher3.util.ui.AbstractLauncherUiTest.startAppFast;
import static com.android.launcher3.util.ui.AbstractLauncherUiTest.startTestActivity;
import static com.android.launcher3.ui.TaplTestsLauncher3Test.getAppPackageName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -58,9 +58,9 @@ import com.android.launcher3.testcomponent.TestCommandReceiver;
import com.android.launcher3.util.TestUtil;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.FailureWatcher;
import com.android.launcher3.util.rule.MutualExclusionRule;
import com.android.launcher3.util.rule.SamplerRule;
import com.android.launcher3.util.rule.ScreenRecordRule;
import com.android.launcher3.util.rule.SkipAfterTimeOutRule;
import com.android.launcher3.util.rule.TestIsolationRule;
import com.android.launcher3.util.rule.TestStabilityRule;
import com.android.launcher3.util.rule.ViewCaptureRule;
@@ -113,7 +113,7 @@ public class FallbackRecentsTest {
public ExtendedLongPressTimeoutRule mLongPressTimeoutRule = new ExtendedLongPressTimeoutRule();
@Rule(order = -1000) // This should be the outermost rule
public MutualExclusionRule mMutualExclusionRule = new MutualExclusionRule();
public SkipAfterTimeOutRule mSkipAfterTimeOutRule = new SkipAfterTimeOutRule();
public FallbackRecentsTest() throws RemoteException {
Instrumentation instrumentation = getInstrumentation();
+1 -1
View File
@@ -22,7 +22,7 @@ filegroup {
"util/TestConstants.java",
"util/Wait.kt",
"util/rule/FailureWatcher.java",
"util/rule/MutualExclusionRule.java",
"util/rule/SkipAfterTimeOutRule.java",
"util/rule/SamplerRule.java",
"util/rule/ScreenRecordRule.java",
"util/rule/ShellCommandRule.java",
@@ -16,20 +16,15 @@
package com.android.launcher3.util.rule;
import android.util.Log;
import org.junit.AssumptionViolatedException;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.junit.runners.model.TestTimedOutException;
import java.util.concurrent.locks.ReentrantLock;
/** Enforces a mutual exclusion to prevent flakiness from overlapping remote test runs. */
public class MutualExclusionRule implements TestRule {
private static final String TAG = "MutualExclusionRule";
private static final ReentrantLock MUTEX = new ReentrantLock();
/** Makes sure that tests are skipped after a timed-out test to avoid test execution overlap. */
public class SkipAfterTimeOutRule implements TestRule {
private static boolean sHadTimeoutException = false;
@Override
public Statement apply(Statement base, Description description) {
@@ -37,15 +32,14 @@ public class MutualExclusionRule implements TestRule {
@Override
public void evaluate() throws Throwable {
try {
Log.d(TAG, "In try-block: Enabling reentrant lock");
MUTEX.lock();
if (sHadTimeoutException) {
throw new AssumptionViolatedException(
"An earlier test had TestTimedOutException");
}
base.evaluate();
} catch (Exception e) {
Log.e(TAG, "Error", e);
} catch (TestTimedOutException e) {
sHadTimeoutException = true;
throw e;
} finally {
Log.d(TAG, "In finally-block: Disabling reentrant lock");
MUTEX.unlock();
}
}
};
@@ -58,10 +58,10 @@ import com.android.launcher3.tapl.TestHelpers;
import com.android.launcher3.util.TestUtil;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.FailureWatcher;
import com.android.launcher3.util.rule.MutualExclusionRule;
import com.android.launcher3.util.rule.SamplerRule;
import com.android.launcher3.util.rule.ScreenRecordRule;
import com.android.launcher3.util.rule.ShellCommandRule;
import com.android.launcher3.util.rule.SkipAfterTimeOutRule;
import com.android.launcher3.util.rule.TestIsolationRule;
import com.android.launcher3.util.rule.TestStabilityRule;
import com.android.launcher3.util.workspace.FavoriteItemsTransaction;
@@ -212,7 +212,7 @@ public abstract class BaseLauncherTaplTest {
public LimitDevicesRule mlimitDevicesRule = new LimitDevicesRule();
@Rule(order = -1000) // This should be the outermost rule
public MutualExclusionRule mMutualExclusionRule = new MutualExclusionRule();
public SkipAfterTimeOutRule mSkipAfterTimeOutRule = new SkipAfterTimeOutRule();
protected void performInitialization() {
reinitializeLauncherData();