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

Commit 2760a780 authored by Lais Andrade's avatar Lais Andrade
Browse files

Fix flaky VibrationThread test with multiple vibrations.

Replace last vibration in test with a predefined click, which is
only completed after the native callback. This should ensure the verify
assertion on the mock callback will always be successful.

This should avoid a flakiness that can happen for one-shot vibrations
that are turned off at the fixed end time and might cause the vibration
to finish before the native callback is triggered and ignored.

Fix: 328784973
Test: atest --rerun-until-failure 1000 com.android.server.vibrator.VibrationThreadTest#vibrate_multipleVibrations_withCancel
Change-Id: I93eb568236a4429b37f11823fc49283b61118164
parent 2cd1f3b2
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -1681,7 +1681,7 @@ public class VibrationThreadTest {
                .addPrimitive(VibrationEffect.Composition.PRIMITIVE_CLICK)
                .compose();
        VibrationEffect effect4 = VibrationEffect.createOneShot(8000, 100);
        VibrationEffect effect5 = VibrationEffect.createOneShot(20, 222);
        VibrationEffect effect5 = VibrationEffect.get(VibrationEffect.EFFECT_CLICK);

        long vibrationId1 = startThreadAndDispatcher(effect1);
        waitForCompletion();
@@ -1745,13 +1745,12 @@ public class VibrationThreadTest {
        verifyCallbacksTriggered(vibrationId4, Vibration.Status.CANCELLED_BY_SCREEN_OFF);
        assertTrue("Tested duration=" + duration4, duration4 < 2000);

        // Effect5: normal oneshot. Don't worry about amplitude, as effect4 may or may not have
        // started.
        // Effect5: played normally after effect4, which may or may not have played.

        verify(mControllerCallbacks).onComplete(eq(VIBRATOR_ID), eq(vibrationId5));
        verifyCallbacksTriggered(vibrationId5, Vibration.Status.FINISHED);

        assertEquals(Arrays.asList(expectedOneShot(20)),
        assertEquals(Arrays.asList(expectedPrebaked(VibrationEffect.EFFECT_CLICK)),
                fakeVibrator.getEffectSegments(vibrationId5));
    }