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

Commit 2b2d81cf authored by Hyundo Moon's avatar Hyundo Moon
Browse files

Fix failing ContentProfileErrorReportUtilsTest

The tests were failing if the test methods' order is changed.
It is because the flag value is stored in a static variable
which doesn't change until BT process ends.
This CL removes the static variable.

Also this CL makes the ContentProfileErrorReportUtilsTest.report()
return a boolean representing the result.

Bug: 317002318
Bug: 294797589
Test: atest ContentProfileErrorReportUtilsTest
      (Also tested changing test methods' order)
Change-Id: I5e63d0bf7dd694caec38c1360ec1372ddf77e00c
parent 4f572bd6
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -34,9 +34,6 @@ public class ContentProfileErrorReportUtils {
    /* Minimum period between two error reports */
    @VisibleForTesting static final long MIN_PERIOD_BETWEEN_TWO_ERROR_REPORTS_MILLIS = 1_000;

    /* Whether reporting is enabled by flags */
    @VisibleForTesting static boolean sEnabled = Flags.contentProfilesErrorsMetrics();

    @VisibleForTesting static long sLastReportTime = 0;

    /**
@@ -52,10 +49,11 @@ public class ContentProfileErrorReportUtils {
     *     BluetoothStatsLog#BLUETOOTH_CONTENT_PROFILE_ERROR_REPORTED__TYPE__LOG_WARN}
     * @param tag A tag which represents the code location of this error. The values are managed per
     *     each java file.
     * @return true if successfully wrote the error, false otherwise
     */
    public static synchronized void report(int profile, int fileNameEnum, int type, int tag) {
        if (!sEnabled) {
            return;
    public static synchronized boolean report(int profile, int fileNameEnum, int type, int tag) {
        if (!Flags.contentProfilesErrorsMetrics()) {
            return false;
        }

        if (isTooFrequentReport()) {
@@ -66,7 +64,7 @@ public class ContentProfileErrorReportUtils {
                            + fileNameEnum
                            + ", tag="
                            + tag);
            return;
            return false;
        }

        BluetoothStatsLog.write(
@@ -76,6 +74,7 @@ public class ContentProfileErrorReportUtils {
                type,
                tag);
        sLastReportTime = SystemClock.uptimeMillis();
        return true;
    }

    private static boolean isTooFrequentReport() {
+3 −6
Original line number Diff line number Diff line
@@ -40,8 +40,7 @@ public class ContentProfileErrorReportUtilsTest {
        mSetFlagsRule.disableFlags(Flags.FLAG_CONTENT_PROFILES_ERRORS_METRICS);
        long previousReportTimeMillis = ContentProfileErrorReportUtils.sLastReportTime;

        ContentProfileErrorReportUtils.report(0, 0, 0, 0);

        assertThat(ContentProfileErrorReportUtils.report(0, 0, 0, 0)).isFalse();
        // The last report time should not be changed.
        assertThat(ContentProfileErrorReportUtils.sLastReportTime)
                .isEqualTo(previousReportTimeMillis);
@@ -54,8 +53,7 @@ public class ContentProfileErrorReportUtilsTest {
        long lastReportTimeMillisToSet = SystemClock.uptimeMillis();
        ContentProfileErrorReportUtils.sLastReportTime = lastReportTimeMillisToSet;

        ContentProfileErrorReportUtils.report(0, 0, 0, 0);

        assertThat(ContentProfileErrorReportUtils.report(0, 0, 0, 0)).isFalse();
        // The last report time should not be changed.
        assertThat(ContentProfileErrorReportUtils.sLastReportTime)
                .isEqualTo(lastReportTimeMillisToSet);
@@ -72,8 +70,7 @@ public class ContentProfileErrorReportUtilsTest {
                                * 2);
        ContentProfileErrorReportUtils.sLastReportTime = lastReportTimeMillisToSet;

        ContentProfileErrorReportUtils.report(0, 0, 0, 0);

        assertThat(ContentProfileErrorReportUtils.report(0, 0, 0, 0)).isTrue();
        // After the successful report, the last report time should be changed.
        assertThat(ContentProfileErrorReportUtils.sLastReportTime)
                .isGreaterThan(lastReportTimeMillisToSet);