From 3743ca97c735dc0592cb2c28de69db2a841c40a8 Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Thu, 15 May 2025 12:57:36 -0700 Subject: [PATCH] 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 --- .../quickstep/FallbackRecentsTest.java | 6 ++-- tests/src/com/android/launcher3/Android.bp | 2 +- ...ionRule.java => SkipAfterTimeOutRule.java} | 28 ++++++++----------- .../util/ui/BaseLauncherTaplTest.java | 4 +-- 4 files changed, 17 insertions(+), 23 deletions(-) rename tests/src/com/android/launcher3/util/rule/{MutualExclusionRule.java => SkipAfterTimeOutRule.java} (61%) diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index c9d8860b28..517e4a1a17 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -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(); diff --git a/tests/src/com/android/launcher3/Android.bp b/tests/src/com/android/launcher3/Android.bp index f40c027ba4..f6a4c7f377 100644 --- a/tests/src/com/android/launcher3/Android.bp +++ b/tests/src/com/android/launcher3/Android.bp @@ -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", diff --git a/tests/src/com/android/launcher3/util/rule/MutualExclusionRule.java b/tests/src/com/android/launcher3/util/rule/SkipAfterTimeOutRule.java similarity index 61% rename from tests/src/com/android/launcher3/util/rule/MutualExclusionRule.java rename to tests/src/com/android/launcher3/util/rule/SkipAfterTimeOutRule.java index f6e8199d38..bc906ca876 100644 --- a/tests/src/com/android/launcher3/util/rule/MutualExclusionRule.java +++ b/tests/src/com/android/launcher3/util/rule/SkipAfterTimeOutRule.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(); } } }; diff --git a/tests/src/com/android/launcher3/util/ui/BaseLauncherTaplTest.java b/tests/src/com/android/launcher3/util/ui/BaseLauncherTaplTest.java index b743f575fb..2f126ea14b 100644 --- a/tests/src/com/android/launcher3/util/ui/BaseLauncherTaplTest.java +++ b/tests/src/com/android/launcher3/util/ui/BaseLauncherTaplTest.java @@ -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();