From 63c90bb8dfa2515f176a9c6b5058ad666f9e04a5 Mon Sep 17 00:00:00 2001 From: Dmitri Plotnikov Date: Tue, 20 Jul 2021 16:03:11 -0700 Subject: [PATCH] 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 --- .../os/BatteryStatsSamplingTimerTest.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java index dd814e651edeb..53845a797ff4b 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java @@ -56,7 +56,6 @@ public class BatteryStatsSamplingTimerTest extends TestCase { } @SmallTest - @SkipPresubmit("b/180015146") public void testEndSampleAndContinueWhenTimeOrCountDecreases() throws Exception { final MockClocks clocks = new MockClocks(); 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)); // 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); 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(10, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); - // This is less than we currently have, so we should end our sample and continue with the - // entire amount updated here. - timer.update(50, 5, SystemClock.elapsedRealtime() * 1000); + // This is less than we currently have, so we should end our sample. + timer.update(30, 3, 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(15, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));