Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 68e85785 authored by vadimt's avatar vadimt
Browse files

Not trying to disable running tests after a failed finalizer

Turns out there is no good way to know that an exception comes from a
finalizer.

Change-Id: I0cb2c518d0b7dc20ad7734ed46ba6af1b8a9d36e
parent 9f3cf1aa
Loading
Loading
Loading
Loading
+0 −33
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ 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;
@@ -16,7 +15,6 @@ import java.io.IOException;

public class FailureWatcher extends TestWatcher {
    private static final String TAG = "FailureWatcher";
    private static boolean sHadFailedTestDeinitialization;
    final private UiDevice mDevice;

    public FailureWatcher(UiDevice device) {
@@ -62,35 +60,4 @@ public class FailureWatcher extends TestWatcher {

        device.takeScreenshot(new File(pathname));
    }

    @Override
    public Statement apply(Statement base, Description description) {
        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                if (sHadFailedTestDeinitialization) {
                    Log.d(TAG, "Skipping due to a recent test deinitialization failure: " +
                            description.getDisplayName());
                    return;
                }

                try {
                    FailureWatcher.super.apply(base, description).evaluate();
                } catch (Throwable e) {
                    final String stackTrace = Log.getStackTraceString(e);
                    if (!stackTrace.contains(
                            "androidx.test.internal.runner.junit4.statement.RunBefores.evaluate")) {
                        // Test failed to deinitialize. Since the global state is probably
                        // corrupted, won't execute other tests.
                        Log.d(TAG,
                                "Detected an exception from test finalizer, will skip further "
                                        + "tests: " + stackTrace);
                        sHadFailedTestDeinitialization = true;
                    }
                    throw e;
                }
            }
        };
    }
}