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

Commit 12ea0804 authored by Yisroel Forta's avatar Yisroel Forta
Browse files

Fix start info clock tests

Both of these tests are flaky due to how quickly the test can run,
resulting in the clock not actually advancing as expected.

For the ordering test, add a 1ms delay between timestamps thereby
guaranteeing that the time advances.

For the persistence test, change the check to include equals as a valid
pass case. This is ok because it still ensures that the clock was loaded
from disk rather than being initialized as new.

Test: run each test 15 times, all pass
Bug: 361874703
Flag: EXEMPT - test fix
Change-Id: I17b0612795b6ffceaaff60c975a951202a6272e4
parent 21a1d068
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -509,8 +509,12 @@ public class ApplicationStartInfoTest {

        mAppStartInfoTracker.handleProcessBroadcastStart(3, app, buildIntent(COMPONENT),
                false /* isAlarm */);
        // Add a brief delay between timestamps to make sure the clock, which is in milliseconds has
        // actually incremented.
        sleep(1);
        mAppStartInfoTracker.handleProcessBroadcastStart(2, app, buildIntent(COMPONENT),
                false /* isAlarm */);
        sleep(1);
        mAppStartInfoTracker.handleProcessBroadcastStart(1, app, buildIntent(COMPONENT),
                false /* isAlarm */);

@@ -557,9 +561,10 @@ public class ApplicationStartInfoTest {
        // Now load from disk.
        mAppStartInfoTracker.loadExistingProcessStartInfo();

        // Confirm clock has been set and that its current time is greater than the previous one.
        // Confirm clock has been set and that its current time is greater than or equal to the
        // previous one, thereby ensuring it was loaded from disk.
        assertNotNull(mAppStartInfoTracker.mMonotonicClock);
        assertTrue(mAppStartInfoTracker.mMonotonicClock.monotonicTime() > originalMonotonicTime);
        assertTrue(mAppStartInfoTracker.mMonotonicClock.monotonicTime() >= originalMonotonicTime);
    }

    private static <T> void setFieldValue(Class clazz, Object obj, String fieldName, T val) {