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

Commit 63c90bb8 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Fix BatteryStatsSamplingTimerTest#testEndSampleAndContinueWhenTimeOrCountDecreases

The test failure was caused by https://cs.android.com/android/_/android/platform/frameworks/base/+/7293dfca7cbedbc6eb2414f0c1e8f97c5f106f88
Bug: 180015146
Test: atest FrameworksCoreTests:BatteryStatsSamplingTimerTest#testEndSampleAndContinueWhenTimeOrCountDecreases

Change-Id: I79b5bd9526b6a0e7dad236b14548dca362ce1449
parent 59c65885
Loading
Loading
Loading
Loading
+11 −5
Original line number Original line Diff line number Diff line
@@ -56,7 +56,6 @@ public class BatteryStatsSamplingTimerTest extends TestCase {
    }
    }


    @SmallTest
    @SmallTest
    @SkipPresubmit("b/180015146")
    public void testEndSampleAndContinueWhenTimeOrCountDecreases() throws Exception {
    public void testEndSampleAndContinueWhenTimeOrCountDecreases() throws Exception {
        final MockClocks clocks = new MockClocks();
        final MockClocks clocks = new MockClocks();
        final BatteryStatsImpl.TimeBase timeBase = Mockito.mock(BatteryStatsImpl.TimeBase.class);
        final BatteryStatsImpl.TimeBase timeBase = Mockito.mock(BatteryStatsImpl.TimeBase.class);
@@ -72,7 +71,10 @@ public class BatteryStatsSamplingTimerTest extends TestCase {
        assertEquals(0, timer.getTotalTimeLocked(200, BatteryStats.STATS_SINCE_CHARGED));
        assertEquals(0, timer.getTotalTimeLocked(200, BatteryStats.STATS_SINCE_CHARGED));


        // This is less than we currently have, so we will end the sample. Time isn't running, so
        // This is less than we currently have, so we will end the sample. Time isn't running, so
        // nothing should happen.
        // nothing should happen, except that tracking will stop.
        timer.update(0, 0, SystemClock.elapsedRealtime() * 1000);

        // Start tracking again
        timer.update(0, 0, SystemClock.elapsedRealtime() * 1000);
        timer.update(0, 0, SystemClock.elapsedRealtime() * 1000);


        assertEquals(0, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
        assertEquals(0, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
@@ -86,9 +88,13 @@ public class BatteryStatsSamplingTimerTest extends TestCase {
        assertEquals(100, timer.getTotalTimeLocked(200, BatteryStats.STATS_SINCE_CHARGED));
        assertEquals(100, timer.getTotalTimeLocked(200, BatteryStats.STATS_SINCE_CHARGED));
        assertEquals(10, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
        assertEquals(10, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));


        // This is less than we currently have, so we should end our sample and continue with the
        // This is less than we currently have, so we should end our sample.
        // entire amount updated here.
        timer.update(30, 3, SystemClock.elapsedRealtime() * 1000);
        timer.update(50, 5, SystemClock.elapsedRealtime() * 1000);

        // Restart tracking
        timer.update(30, 3, SystemClock.elapsedRealtime() * 1000);

        timer.add(50, 5);


        assertEquals(150, timer.getTotalTimeLocked(200, BatteryStats.STATS_SINCE_CHARGED));
        assertEquals(150, timer.getTotalTimeLocked(200, BatteryStats.STATS_SINCE_CHARGED));
        assertEquals(15, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
        assertEquals(15, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));