From 2c6316be46e258a91d414916fcfab98f8dece0ea Mon Sep 17 00:00:00 2001 From: vadimt Date: Tue, 21 Jan 2020 18:55:28 -0800 Subject: [PATCH] Adding auto-investigation of one more flake Reshuffling the tests to make the investigator the outmost rule and run the code that throws the original exception inside the investigator. Change-Id: I714717a9b616862db5ce59116138ba7ea6ceb971 --- .../quickstep/FallbackRecentsTest.java | 5 +- .../StartLauncherViaGestureTests.java | 3 -- .../launcher3/ui/AbstractLauncherUiTest.java | 8 +-- .../util/rule/FailureInvestigator.java | 6 +++ .../util/rule/FailureRewriterRule.java | 54 +++++++++++++++++++ .../launcher3/util/rule/FailureWatcher.java | 27 ---------- .../util/rule/TestStabilityRule.java | 5 +- 7 files changed, 72 insertions(+), 36 deletions(-) create mode 100644 tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index 85cffaa107..04e32b0d28 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -56,6 +56,7 @@ import com.android.launcher3.tapl.OverviewTask; import com.android.launcher3.tapl.TestHelpers; import com.android.launcher3.testcomponent.TestCommandReceiver; import com.android.launcher3.util.Wait; +import com.android.launcher3.util.rule.FailureRewriterRule; import com.android.launcher3.util.rule.FailureWatcher; import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch; import com.android.quickstep.views.RecentsView; @@ -99,7 +100,9 @@ public class FallbackRecentsTest { Utilities.enableRunningInTestHarnessForTests(); } - mOrderSensitiveRules = RuleChain.outerRule(new NavigationModeSwitchRule(mLauncher)) + mOrderSensitiveRules = RuleChain + .outerRule(new FailureRewriterRule()) + .around(new NavigationModeSwitchRule(mLauncher)) .around(new FailureWatcher(mDevice)); mOtherLauncherActivity = context.getPackageManager().queryIntentActivities( diff --git a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java index 891bf240df..3d048a6413 100644 --- a/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java +++ b/quickstep/tests/src/com/android/quickstep/StartLauncherViaGestureTests.java @@ -18,9 +18,6 @@ package com.android.quickstep; import static com.android.launcher3.util.RaceConditionReproducer.enterEvt; import static com.android.launcher3.util.RaceConditionReproducer.exitEvt; -import static com.android.launcher3.util.rule.TestStabilityRule.PLATFORM_PRESUBMIT; -import static com.android.launcher3.util.rule.TestStabilityRule.RUN_FLAFOR; -import static com.android.launcher3.util.rule.TestStabilityRule.UNBUNDLED_PRESUBMIT; import android.content.Intent; diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index 60dad12483..ace04f3156 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -62,6 +62,7 @@ import com.android.launcher3.util.ContentWriter; import com.android.launcher3.util.LooperExecutor; import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.util.Wait; +import com.android.launcher3.util.rule.FailureRewriterRule; import com.android.launcher3.util.rule.FailureWatcher; import com.android.launcher3.util.rule.LauncherActivityRule; import com.android.launcher3.util.rule.ShellCommandRule; @@ -161,9 +162,10 @@ public abstract class AbstractLauncherUiTest { @Rule public TestRule mOrderSensitiveRules = RuleChain. - outerRule(new TestStabilityRule()). - around(mActivityMonitor). - around(getRulesInsideActivityMonitor()); + outerRule(new FailureRewriterRule()) + .around(new TestStabilityRule()) + .around(mActivityMonitor) + .around(getRulesInsideActivityMonitor()); public UiDevice getDevice() { return mDevice; diff --git a/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java b/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java index 56c885d85b..cada8d6fb1 100644 --- a/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java +++ b/tests/src/com/android/launcher3/util/rule/FailureInvestigator.java @@ -47,6 +47,12 @@ class FailureInvestigator { logSinceTestsStart)) { return 147845913; } + } else if (matches("java.lang.AssertionError: Launcher build match not found", exception)) { + if (matches( + "TestStabilityRule: Launcher package: com.google.android.setupwizard", + logSinceTestsStart)) { + return 145935261; + } } return 0; diff --git a/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java b/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java new file mode 100644 index 0000000000..4cb309a34a --- /dev/null +++ b/tests/src/com/android/launcher3/util/rule/FailureRewriterRule.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.util.rule; + +import android.util.Log; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class FailureRewriterRule implements TestRule { + private static final String TAG = "FailureRewriter"; + + private static final String testsStartTime = + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()); + + @Override + public Statement apply(Statement base, Description description) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + try { + base.evaluate(); + } catch (Throwable e) { + final int bug = + FailureInvestigator.getBugForFailure(e.toString(), testsStartTime); + if (bug == 0) throw e; + + Log.e(TAG, "Known bug found for the original failure " + + android.util.Log.getStackTraceString(e)); + throw new AssertionError( + "Detected a failure that matches a known bug b/" + bug); + } + } + }; + } +} diff --git a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java index feb89b925f..cdda0f0dcc 100644 --- a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java +++ b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java @@ -8,13 +8,10 @@ import androidx.test.uiautomator.UiDevice; import org.junit.rules.TestWatcher; import org.junit.runner.Description; -import org.junit.runners.model.Statement; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Date; public class FailureWatcher extends TestWatcher { private static final String TAG = "FailureWatcher"; @@ -38,30 +35,6 @@ public class FailureWatcher extends TestWatcher { } } - private static final String testsStartTime = - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()); - - @Override - public Statement apply(Statement base, Description description) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - try { - base.evaluate(); - } catch (Throwable e) { - final int bug = - FailureInvestigator.getBugForFailure(e.toString(), testsStartTime); - if (bug == 0) throw e; - - Log.e(TAG, "Known bug found for the original failure " - + android.util.Log.getStackTraceString(e)); - throw new AssertionError( - "Detected a failure that matches a known bug b/" + bug); - } - } - }; - } - @Override protected void failed(Throwable e, Description description) { onError(mDevice, description, e); diff --git a/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java b/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java index b394bcbd18..1feb4e736a 100644 --- a/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java +++ b/tests/src/com/android/launcher3/util/rule/TestStabilityRule.java @@ -58,7 +58,7 @@ public class TestStabilityRule implements TestRule { public static final int PLATFORM_PRESUBMIT = 0x8; public static final int PLATFORM_POSTSUBMIT = 0x10; - public static final int RUN_FLAFOR = getRunFlavor(); + private static int sRunFlavor; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @@ -73,7 +73,8 @@ public class TestStabilityRule implements TestRule { return new Statement() { @Override public void evaluate() throws Throwable { - if ((stability.flavors() & RUN_FLAFOR) != 0) { + if (sRunFlavor == 0) sRunFlavor = getRunFlavor(); + if ((stability.flavors() & sRunFlavor) != 0) { Log.d(TAG, "Running " + description.getDisplayName()); base.evaluate(); } else {