Use FakeTimer in test to avoid flakiness.

**Root cause**
ScreenFlashNotificationColorDialogFragment creates Timer which spawns
unmanageable threads for tests. Also, the test itself uses Thread.sleep
which makes it non-destermistic.

Bug: 279082331
Test: atest ScreenFlashNotificationColorDialogFragmentTest --iteration
20

Change-Id: Id49c8d402a0578f8297ca12fe49da304c7a988d8
This commit is contained in:
Chun-Ku Lin
2023-06-15 01:45:52 +00:00
parent 8344f256e0
commit 802978fd80
3 changed files with 166 additions and 36 deletions

View File

@@ -119,7 +119,7 @@ public class ScreenFlashNotificationColorDialogFragment extends DialogFragment i
synchronized (this) {
if (mTimer != null) mTimer.cancel();
mTimer = new Timer();
mTimer = createTimer();
if (mIsPreview) {
mTimer.schedule(getStopTask(), 0);
startDelay = BETWEEN_STOP_AND_START_DELAY_MS;
@@ -176,4 +176,8 @@ public class ScreenFlashNotificationColorDialogFragment extends DialogFragment i
getContext().sendBroadcast(stopIntent);
mIsPreview = false;
}
Timer createTimer() {
return new Timer();
}
}