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

Commit b5cff963 authored by Kweku Adams's avatar Kweku Adams
Browse files

Fix test flakiness.

The default mocked value (0) was causing some code to run that would
occasionally interfere with tests, making them flaky. Setting the value
to the right "unknown" value disables that and prevents the test flakes.

Also add a safety check and escape valve in case something was missed
and things go wrong in production.

Bug: 236261941
Test: atest --rerun-until-failure 25 FrameworksMockingServicesTests:FlexibilityControllerTest
Change-Id: I5d14329e5ba656af77ccdbd39d28d53080c0c47d
parent b0c84bce
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -972,6 +972,20 @@ public final class FlexibilityController extends StateController {
            synchronized (mLock) {
                final long earliest = getLifeCycleBeginningElapsedLocked(js);
                final long latest = getLifeCycleEndElapsedLocked(js, nowElapsed, earliest);
                if (latest <= earliest) {
                    // Something has gone horribly wrong. This has only occurred on incorrectly
                    // configured tests, but add a check here for safety.
                    Slog.wtf(TAG, "Got invalid latest when scheduling alarm."
                            + " Prefetch=" + js.getJob().isPrefetch());
                    // Since things have gone wrong, the safest and most reliable thing to do is
                    // stop applying flex policy to the job.
                    mFlexibilityTracker.setNumDroppedFlexibleConstraints(js,
                            js.getNumAppliedFlexibleConstraints());
                    mJobsToCheck.add(js);
                    mHandler.sendEmptyMessage(MSG_CHECK_JOBS);
                    return;
                }

                final long nextTimeElapsed =
                        getNextConstraintDropTimeElapsedLocked(js, earliest, latest);

+1 −0
Original line number Diff line number Diff line
@@ -180,6 +180,7 @@ public class FlexibilityControllerTest {
        JobSchedulerService.sElapsedRealtimeClock =
                Clock.fixed(Instant.ofEpochMilli(FROZEN_TIME), ZoneOffset.UTC);
        // Initialize real objects.
        doReturn(Long.MAX_VALUE).when(mPrefetchController).getNextEstimatedLaunchTimeLocked(any());
        ArgumentCaptor<BroadcastReceiver> receiverCaptor =
                ArgumentCaptor.forClass(BroadcastReceiver.class);
        mFlexibilityController = new FlexibilityController(mJobSchedulerService,