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

Commit 2a74011a authored by Robin Lee's avatar Robin Lee
Browse files

Make ShellTestCase try to delete TestableLooper

TestableLooper is dangerous due to the ease of adding it with an
annotation and the poor explanation of what the implications of doing
this are (it is REQUIRED to manually clean up in an @After block to
avoid memory leaks which break large test suites).

The majority of tests in wm/shell are inheriting from ShellTestCase so
we can claw some memory back by having the superclass try to do the
right thing even if individual tests forget. This should become a
warning and eventually an error, and eventually a full ban.

Test: atest WMShellUnitTests
Bug: 261039202
Bug: 419430883
Flag: EXEMPT bugfix
Change-Id: Ie40c897d1cd6a86f8013b6c4372797d31482ed59
parent 896bf415
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.platform.test.flag.junit.SetFlagsRule;
import android.testing.TestableContext;
import android.testing.TestableLooper;

import androidx.test.platform.app.InstrumentationRegistry;

@@ -80,6 +81,16 @@ public abstract class ShellTestCase {

    @After
    public void shellTearDown() {
        // In case someone set up a TestableLooper during the test, get rid of it because
        // TestableLooper intrinsically leaks all past test method member fields in a
        // big static list.
        //
        // TODO (b/261039202): don't use TestableLooper in WmShell tests at all.
        if (TestableLooper.get(this) != null) {
            TestableLooper.get(this).processAllMessages();
            TestableLooper.remove(this);
        }

        InstrumentationRegistry
                .getInstrumentation()
                .getUiAutomation()