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

Commit 03b62976 authored by Chris Li's avatar Chris Li
Browse files

Fix flaky ActivityThreadTest

Always reset application configuration after test to prevent it from
affecting other test cases.

Fix: 279720755
Test: atest FrameworksCoreTests:ActivityThreadTest
Change-Id: I726a979da802abf4835f9893d4d8247d70f5537b
parent 6927452e
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ public class ActivityThreadTest {
                    false /* launchActivity */);

    private WindowTokenClientController mOriginalWindowTokenClientController;
    private Configuration mOriginalAppConfig;

    private ArrayList<VirtualDisplay> mCreatedVirtualDisplays;

@@ -114,6 +115,8 @@ public class ActivityThreadTest {
        // Keep track of the original controller, so that it can be used to restore in tearDown()
        // when there is override in some test cases.
        mOriginalWindowTokenClientController = WindowTokenClientController.getInstance();
        mOriginalAppConfig = new Configuration(ActivityThread.currentActivityThread()
                .getConfiguration());
    }

    @After
@@ -123,6 +126,8 @@ public class ActivityThreadTest {
            mCreatedVirtualDisplays = null;
        }
        WindowTokenClientController.overrideForTesting(mOriginalWindowTokenClientController);
        InstrumentationRegistry.getInstrumentation().runOnMainSync(
                () -> restoreConfig(ActivityThread.currentActivityThread(), mOriginalAppConfig));
    }

    @Test
@@ -564,16 +569,10 @@ public class ActivityThreadTest {
            activityThread.updatePendingConfiguration(newAppConfig);
            activityThread.handleConfigurationChanged(newAppConfig, DEVICE_ID_INVALID);

            try {
            assertEquals("Virtual display orientation must not change when process"
                            + " configuration orientation changes.",
                    originalVirtualDisplayOrientation,
                    virtualDisplayContext.getResources().getConfiguration().orientation);
            } finally {
                // Make sure to reset the process config to prevent side effects to other
                // tests.
                restoreConfig(activityThread, originalAppConfig);
            }
        });
    }