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

Commit 4b7c4adc authored by Lais Andrade's avatar Lais Andrade
Browse files

Fix flaky waveform vibration test

Use Mockito.inOrder verifier to check waveform amplitues are set in the
expected pattern order and use a single timeout for the entire waveform
in the test.

Bug: 173347869
Test: atest FrameworksServicesTests:VibratorServiceTest
Change-Id: Ib1780746027f15ade2360b5c4f740bccc919b57a
parent 2f5313a7
Loading
Loading
Loading
Loading
+10 −17
Original line number Diff line number Diff line
@@ -452,22 +452,15 @@ public class VibratorServiceTest {
                new long[]{10, 10, 10}, new int[]{100, 200, 50}, -1);
        vibrate(service, effect);

        verify(mNativeWrapperMock).vibratorOff();

        // Wait for VibrateThread to turn vibrator ON with total timing and no callback.
        Thread.sleep(5);
        verify(mNativeWrapperMock).vibratorOn(eq(30L), anyLong());

        // First amplitude set right away.
        verify(mNativeWrapperMock).vibratorSetAmplitude(eq(100));

        // Second amplitude set after first timing is finished.
        Thread.sleep(10);
        verify(mNativeWrapperMock).vibratorSetAmplitude(eq(200));

        // Third amplitude set after second timing is finished.
        Thread.sleep(10);
        verify(mNativeWrapperMock).vibratorSetAmplitude(eq(50));
        // Wait for VibrateThread to finish: 10ms 100, 10ms 200, 10ms 50.
        Thread.sleep(40);
        InOrder inOrderVerifier = inOrder(mNativeWrapperMock);
        inOrderVerifier.verify(mNativeWrapperMock).vibratorOff();
        inOrderVerifier.verify(mNativeWrapperMock).vibratorOn(eq(30L), anyLong());
        inOrderVerifier.verify(mNativeWrapperMock).vibratorSetAmplitude(eq(100));
        inOrderVerifier.verify(mNativeWrapperMock).vibratorSetAmplitude(eq(200));
        inOrderVerifier.verify(mNativeWrapperMock).vibratorSetAmplitude(eq(50));
        inOrderVerifier.verify(mNativeWrapperMock).vibratorOff();
    }

    @Test
@@ -696,7 +689,7 @@ public class VibratorServiceTest {
                HAPTIC_FEEDBACK_ATTRS);

        // Waveform effect runs on a separate thread.
        Thread.sleep(5);
        Thread.sleep(15);

        // Alarm vibration is never scaled.
        verify(mNativeWrapperMock).vibratorSetAmplitude(eq(100));