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

Commit 81db22ff authored by fionaxu's avatar fionaxu
Browse files

fix flaky SmsDispatcherControllerTest

flaky test is likely due to the short wait time. SmsDispatcherController
might not handle the Ims Network state change yet, so it still think the
underlying tech is Cdma or Gsm rather than ImsGsmSms/ImsCdmaSms. The fix
is using waitForHandlerAction which is more deterministic.

Bug: 78358733
Test: runtest SmsDispatcherControllerTest
Change-Id: Ibb5a2022278eee288f12d2f025cf7e34516d0114
parent d56c5328
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ public class SmsDispatchersControllerTest extends TelephonyTest {
    private ImsSmsDispatcherTestHandler mImsSmsDispatcherTestHandler;
    private boolean mInjectionCallbackTriggered = false;
    private static final String TEST_INTENT = "com.android.internal.telephony.TEST_INTENT";
    private static final int TEST_TIMEOUT = 5000;

    private class ImsSmsDispatcherTestHandler extends HandlerThread {

@@ -87,7 +88,7 @@ public class SmsDispatchersControllerTest extends TelephonyTest {
        super.tearDown();
    }

    @Test @SmallTest @FlakyTest @Ignore
    @Test @SmallTest @FlakyTest
    public void testSmsHandleStateUpdate() throws Exception {
        assertEquals(SmsConstants.FORMAT_UNKNOWN, mSmsDispatchersController.getImsSmsFormat());
        //Mock ImsNetWorkStateChange with GSM phone type
@@ -101,13 +102,13 @@ public class SmsDispatchersControllerTest extends TelephonyTest {
        assertTrue(mSmsDispatchersController.isIms());
    }

    @Test @SmallTest @FlakyTest @Ignore
    @Test @SmallTest @FlakyTest
    public void testSendImsGmsTest() throws Exception {
        switchImsSmsFormat(PhoneConstants.PHONE_TYPE_GSM);
        mSmsDispatchersController.sendText("111"/* desAddr*/, "222" /*scAddr*/, TAG,
                null, null, null, null, false, -1, false, -1);
        verify(mSimulatedCommandsVerifier).sendImsGsmSms(eq("038122f2"),
                eq("0100038111f1000014c9f67cda9c12d37378983e4697e5d4f29c0e"), eq(0), eq(0),
        verify(mSimulatedCommandsVerifier).sendImsGsmSms(eq("038122F2"),
                eq("0100038111F100001CD3F69C989EC3C3F431BA2C9F0FDF6EBAFCCD6697E5D4F29C0E"), eq(0), eq(0),
                any(Message.class));
    }

@@ -177,6 +178,9 @@ public class SmsDispatchersControllerTest extends TelephonyTest {
        mSimulatedCommands.setImsRegistrationState(new int[]{1, phoneType});
        mSimulatedCommands.notifyImsNetworkStateChanged();
        /* wait for async msg get handled */
        waitForMs(200);
        waitForHandlerAction(mSmsDispatchersController, TEST_TIMEOUT);
        /* handle EVENT_IMS_STATE_DONE */
        waitForHandlerAction(mSmsDispatchersController, TEST_TIMEOUT);
        assertTrue(mSmsDispatchersController.isIms());
    }
}