From eaa58de99152c95f22b094393221627d54477c6b Mon Sep 17 00:00:00 2001 From: Junyu Lai Date: Wed, 22 Dec 2021 15:50:13 +0000 Subject: [PATCH] [MS17.2] Fix remaining daily budget assertion Currently, the test didn't mock data usage of the month. Thus, when asserting remaining budget, the calculation always assumes there is no used data, hence wrong budget value is expected. See #getRemainingDailyBudget. This change makes data usage of this month includes the bytes used today. And adjust the policy limit accordingly. Test: atest MultipathPolicyTrackerTest Bug: 204830222 Change-Id: I3ca6505f8d502047485ba3676f16fbc474117cc1 --- .../MultipathPolicyTrackerTest.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/unit/java/com/android/server/connectivity/MultipathPolicyTrackerTest.java b/tests/unit/java/com/android/server/connectivity/MultipathPolicyTrackerTest.java index a3da05d439..349ca5662e 100644 --- a/tests/unit/java/com/android/server/connectivity/MultipathPolicyTrackerTest.java +++ b/tests/unit/java/com/android/server/connectivity/MultipathPolicyTrackerTest.java @@ -31,6 +31,7 @@ import static com.android.server.net.NetworkPolicyManagerService.OPPORTUNISTIC_Q import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doCallRealMethod; @@ -236,9 +237,7 @@ public class MultipathPolicyTrackerTest { .thenReturn((int) defaultResSetting); when(mNetworkStatsManagerInternal.getNetworkTotalBytes( - any(), - eq(startOfDay.toInstant().toEpochMilli()), - eq(now.toInstant().toEpochMilli()))).thenReturn(usedBytesToday); + any(), anyLong(), anyLong())).thenReturn(usedBytesToday); ArgumentCaptor networkCallback = ArgumentCaptor.forClass(ConnectivityManager.NetworkCallback.class); @@ -291,8 +290,10 @@ public class MultipathPolicyTrackerTest { testGetMultipathPreference( DataUnit.MEGABYTES.toBytes(7) /* usedBytesToday */, OPPORTUNISTIC_QUOTA_UNKNOWN, - // 29 days from Apr. 2nd to May 1st - DataUnit.MEGABYTES.toBytes(15 * 29 * 20) /* policyWarning */, + // Remaining days are 29 days from Apr. 2nd to May 1st. + // Set limit so that 15MB * remaining days will be 5% of the remaining limit, + // so it will be 15 * 29 / 0.05 + used bytes. + DataUnit.MEGABYTES.toBytes(15 * 29 * 20 + 7) /* policyWarning */, LIMIT_DISABLED, DataUnit.MEGABYTES.toBytes(12) /* defaultGlobalSetting */, 2_500_000 /* defaultResSetting */, @@ -308,9 +309,11 @@ public class MultipathPolicyTrackerTest { testGetMultipathPreference( DataUnit.MEGABYTES.toBytes(7) /* usedBytesToday */, OPPORTUNISTIC_QUOTA_UNKNOWN, - // 29 days from Apr. 2nd to May 1st POLICY_SNOOZED /* policyWarning */, - DataUnit.MEGABYTES.toBytes(15 * 29 * 20) /* policyLimit */, + // Remaining days are 29 days from Apr. 2nd to May 1st. + // Set limit so that 15MB * remaining days will be 5% of the remaining limit, + // so it will be 15 * 29 / 0.05 + used bytes. + DataUnit.MEGABYTES.toBytes(15 * 29 * 20 + 7) /* policyLimit */, DataUnit.MEGABYTES.toBytes(12) /* defaultGlobalSetting */, 2_500_000 /* defaultResSetting */, false /* roaming */);