Fix flaky WindowTokenClientControllerTest

Create a new instance for testing instead of using the app's real
instance.

The failure only happens once and likely to be an isolated one. Likely to be a side effect of using the application's real instance.

Fix: 293161156
Test: atest FrameworksCoreTests:WindowTokenClientControllerTest
Change-Id: I77f0e34066c61f1f5aaf95551e6d58cf96d112b4
This commit is contained in:
Chris Li
2023-07-26 21:57:22 +08:00
parent 6927452e34
commit ff97716a3a
2 changed files with 7 additions and 1 deletions

View File

@@ -73,6 +73,12 @@ public class WindowTokenClientController {
}
}
/** Creates a new instance for test only. */
@VisibleForTesting
public static WindowTokenClientController createInstanceForTesting() {
return new WindowTokenClientController();
}
private WindowTokenClientController() {}
/**

View File

@@ -76,7 +76,7 @@ public class WindowTokenClientControllerTest {
mOriginalWindowManagerService = WindowManagerGlobal.getWindowManagerService();
WindowManagerGlobal.overrideWindowManagerServiceForTesting(mWindowManagerService);
doReturn(mClientToken).when(mWindowTokenClient).asBinder();
mController = spy(WindowTokenClientController.getInstance());
mController = spy(WindowTokenClientController.createInstanceForTesting());
}
@After