flaky unit test
fionaxu [Thu, 18 May 2017 00:56:40 +0000 (17:56 -0700)]
Test: Telephony unit test
Bug: 29579544
Change-Id: I4057fb0c9651437e91f925aebb110be75cf7d459

tests/telephonytests/src/com/android/internal/telephony/CarrierActionAgentTest.java
tests/telephonytests/src/com/android/internal/telephony/ContextFixture.java
tests/telephonytests/src/com/android/internal/telephony/TelephonyTest.java
tests/telephonytests/src/com/android/internal/telephony/dataconnection/DcTrackerTest.java

index cc72463..5a58c76 100644 (file)
@@ -24,12 +24,10 @@ import static org.mockito.Mockito.verify;
 
 import android.database.ContentObserver;
 import android.net.Uri;
-import android.os.Bundle;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.Message;
 import android.provider.Settings;
-import android.test.mock.MockContentProvider;
 import android.test.mock.MockContentResolver;
 import android.test.suitebuilder.annotation.SmallTest;
 
@@ -42,7 +40,6 @@ import org.mockito.Mock;
 public class CarrierActionAgentTest extends TelephonyTest {
     private CarrierActionAgent mCarrierActionAgentUT;
     private FakeContentResolver mFakeContentResolver;
-    private FakeContentProvider mFakeContentProvider;
     private static int DATA_CARRIER_ACTION_EVENT = 0;
     private static int RADIO_CARRIER_ACTION_EVENT = 1;
     @Mock
@@ -63,23 +60,6 @@ public class CarrierActionAgentTest extends TelephonyTest {
         }
     }
 
-    private class FakeContentProvider extends MockContentProvider {
-        private int mExpectedValue;
-        public void simulateChange(Uri uri) {
-            mFakeContentResolver.notifyChange(uri, null);
-        }
-        @Override
-        public Bundle call(String method, String request, Bundle args) {
-            Bundle result = new Bundle();
-            if (Settings.CALL_METHOD_GET_GLOBAL.equals(method)) {
-                result.putString(Settings.NameValueTable.VALUE, Integer.toString(mExpectedValue));
-            } else {
-                mExpectedValue = Integer.parseInt(args.getString(Settings.NameValueTable.VALUE));
-            }
-            return result;
-        }
-    }
-
     private class CarrierActionAgentHandler extends HandlerThread {
 
         private CarrierActionAgentHandler(String name) {
@@ -104,8 +84,6 @@ public class CarrierActionAgentTest extends TelephonyTest {
         logd("CarrierActionAgentTest +Setup!");
         super.setUp(getClass().getSimpleName());
         mFakeContentResolver = new FakeContentResolver();
-        mFakeContentProvider = new FakeContentProvider();
-        mFakeContentResolver.addProvider(Settings.AUTHORITY, mFakeContentProvider);
         doReturn(mFakeContentResolver).when(mContext).getContentResolver();
         new CarrierActionAgentHandler(getClass().getSimpleName()).start();
         waitUntilReady();
@@ -116,8 +94,8 @@ public class CarrierActionAgentTest extends TelephonyTest {
     @SmallTest
     public void testCarrierActionResetOnAPM() {
         Settings.Global.putInt(mFakeContentResolver, Settings.Global.AIRPLANE_MODE_ON, 1);
-        mFakeContentProvider.simulateChange(
-                Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON));
+        mFakeContentResolver.notifyChange(
+                Settings.Global.getUriFor(Settings.Global.AIRPLANE_MODE_ON), null);
         waitForMs(200);
         ArgumentCaptor<Message> message = ArgumentCaptor.forClass(Message.class);
 
index 419e61b..529c5d4 100644 (file)
@@ -530,6 +530,9 @@ public class ContextFixture implements TestFixture<Context> {
         doReturn(mConfiguration).when(mResources).getConfiguration();
 
         mContentResolver.addProvider(Settings.AUTHORITY, mContentProvider);
+        // Settings caches the provider after first get/set call, this is needed to make sure
+        // Settings is using mContentProvider as the cached provider across all tests.
+        Settings.Global.getInt(mContentResolver, Settings.Global.AIRPLANE_MODE_ON, 0);
         mContentResolver.addProvider(ServiceStateTable.AUTHORITY, mContentProvider);
         mPermissionTable.add(PERMISSION_ENABLE_ALL);
     }
index ed5ca43..b38659c 100644 (file)
@@ -41,7 +41,6 @@ import android.os.IDeviceIdleController;
 import android.os.RegistrantList;
 import android.os.ServiceManager;
 import android.provider.BlockedNumberContract;
-import android.provider.Settings;
 import android.telephony.ServiceState;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
@@ -442,9 +441,6 @@ public abstract class TelephonyTest {
         mSST.mSS = mServiceState;
         mServiceManagerMockedServices.put("connectivity_metrics_logger", mConnMetLoggerBinder);
 
-        Settings.Global.putInt(mContext.getContentResolver(),
-                Settings.Global.ENABLE_CELLULAR_ON_BOOT, 1);
-
         setReady(false);
     }
 
index 18caf99..99c09c5 100644 (file)
@@ -281,10 +281,6 @@ public class DcTrackerTest extends TelephonyTest {
 
     @Before
     public void setUp() throws Exception {
-        // set the lazy cp to the real content provider in order to use the real settings
-        ContentResolver realContentResolver = TestApplication.getAppContext().getContentResolver();
-        Settings.Global.getInt(realContentResolver, Settings.Global.MOBILE_DATA, 1);
-
         logd("DcTrackerTest +Setup!");
         super.setUp(getClass().getSimpleName());