Merge "Add a common test library." am: 126a957df5
am: 4343cf32aa Change-Id: I6104a1a677cb2e4978f11be32dfc604ee431d009
This commit is contained in:
@@ -68,10 +68,6 @@ import static android.net.NetworkPolicyManager.RULE_REJECT_ALL;
|
||||
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
|
||||
import static android.net.RouteInfo.RTN_UNREACHABLE;
|
||||
|
||||
import static com.android.internal.util.TestUtils.waitForIdleHandler;
|
||||
import static com.android.internal.util.TestUtils.waitForIdleLooper;
|
||||
import static com.android.internal.util.TestUtils.waitForIdleSerialExecutor;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -196,6 +192,7 @@ import com.android.server.connectivity.Tethering;
|
||||
import com.android.server.connectivity.Vpn;
|
||||
import com.android.server.net.NetworkPinner;
|
||||
import com.android.server.net.NetworkPolicyManagerInternal;
|
||||
import com.android.testutils.HandlerUtilsKt;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -375,19 +372,19 @@ public class ConnectivityServiceTest {
|
||||
|
||||
public void waitForIdle(int timeoutMsAsInt) {
|
||||
long timeoutMs = timeoutMsAsInt;
|
||||
waitForIdleHandler(mService.mHandlerThread, timeoutMs);
|
||||
HandlerUtilsKt.waitForIdle(mService.mHandlerThread, timeoutMs);
|
||||
waitForIdle(mCellNetworkAgent, timeoutMs);
|
||||
waitForIdle(mWiFiNetworkAgent, timeoutMs);
|
||||
waitForIdle(mEthernetNetworkAgent, timeoutMs);
|
||||
waitForIdleHandler(mService.mHandlerThread, timeoutMs);
|
||||
waitForIdleLooper(ConnectivityThread.getInstanceLooper(), timeoutMs);
|
||||
HandlerUtilsKt.waitForIdle(mService.mHandlerThread, timeoutMs);
|
||||
HandlerUtilsKt.waitForIdle(ConnectivityThread.get(), timeoutMs);
|
||||
}
|
||||
|
||||
public void waitForIdle(MockNetworkAgent agent, long timeoutMs) {
|
||||
if (agent == null) {
|
||||
return;
|
||||
}
|
||||
waitForIdleHandler(agent.mHandlerThread, timeoutMs);
|
||||
HandlerUtilsKt.waitForIdle(agent.mHandlerThread, timeoutMs);
|
||||
}
|
||||
|
||||
private void waitForIdle() {
|
||||
@@ -1220,7 +1217,7 @@ public class ConnectivityServiceTest {
|
||||
}
|
||||
|
||||
public void waitForIdle(int timeoutMs) {
|
||||
waitForIdleHandler(mHandlerThread, timeoutMs);
|
||||
HandlerUtilsKt.waitForIdle(mHandlerThread, timeoutMs);
|
||||
}
|
||||
|
||||
public void waitForIdle() {
|
||||
@@ -4107,7 +4104,7 @@ public class ConnectivityServiceTest {
|
||||
}
|
||||
|
||||
public void assertNoCallback() {
|
||||
waitForIdleSerialExecutor(mExecutor, TIMEOUT_MS);
|
||||
HandlerUtilsKt.waitForIdleSerialExecutor(mExecutor, TIMEOUT_MS);
|
||||
CallbackValue cv = mCallbacks.peek();
|
||||
assertNull("Unexpected callback: " + cv, cv);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,6 @@ import static android.net.NetworkTemplate.buildTemplateWifiWildcard;
|
||||
import static android.net.TrafficStats.MB_IN_BYTES;
|
||||
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
|
||||
|
||||
import static com.android.internal.util.TestUtils.waitForIdleHandler;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
@@ -56,6 +54,7 @@ import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.net.VpnInfo;
|
||||
import com.android.server.net.NetworkStatsServiceTest.LatchedHandler;
|
||||
import com.android.testutils.HandlerUtilsKt;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -457,7 +456,7 @@ public class NetworkStatsObserversTest {
|
||||
}
|
||||
|
||||
private void waitForObserverToIdle() {
|
||||
waitForIdleHandler(mObserverHandlerThread, WAIT_TIMEOUT_MS);
|
||||
waitForIdleHandler(mHandler, WAIT_TIMEOUT_MS);
|
||||
HandlerUtilsKt.waitForIdle(mObserverHandlerThread, WAIT_TIMEOUT_MS);
|
||||
HandlerUtilsKt.waitForIdle(mHandler, WAIT_TIMEOUT_MS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ import static android.text.format.DateUtils.HOUR_IN_MILLIS;
|
||||
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
|
||||
import static android.text.format.DateUtils.WEEK_IN_MILLIS;
|
||||
|
||||
import static com.android.internal.util.TestUtils.waitForIdleHandler;
|
||||
import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_POLL;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -104,6 +103,7 @@ import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.util.test.BroadcastInterceptingContext;
|
||||
import com.android.server.net.NetworkStatsService.NetworkStatsSettings;
|
||||
import com.android.server.net.NetworkStatsService.NetworkStatsSettings.Config;
|
||||
import com.android.testutils.HandlerUtilsKt;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
|
||||
@@ -1057,8 +1057,6 @@ public class NetworkStatsServiceTest {
|
||||
expectNetworkStatsSummary(buildEmptyStats());
|
||||
expectNetworkStatsUidDetail(buildEmptyStats());
|
||||
|
||||
|
||||
|
||||
// Register and verify request and that binder was called
|
||||
DataUsageRequest request =
|
||||
mService.registerUsageCallback(mServiceContext.getOpPackageName(), inputRequest,
|
||||
@@ -1070,14 +1068,11 @@ public class NetworkStatsServiceTest {
|
||||
|
||||
// Send dummy message to make sure that any previous message has been handled
|
||||
mHandler.sendMessage(mHandler.obtainMessage(-1));
|
||||
waitForIdleHandler(mHandler, WAIT_TIMEOUT);
|
||||
|
||||
|
||||
HandlerUtilsKt.waitForIdle(mHandler, WAIT_TIMEOUT);
|
||||
|
||||
// Make sure that the caller binder gets connected
|
||||
verify(mBinder).linkToDeath(any(IBinder.DeathRecipient.class), anyInt());
|
||||
|
||||
|
||||
// modify some number on wifi, and trigger poll event
|
||||
// not enough traffic to call data usage callback
|
||||
incrementCurrentTime(HOUR_IN_MILLIS);
|
||||
@@ -1410,7 +1405,7 @@ public class NetworkStatsServiceTest {
|
||||
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
|
||||
// Send dummy message to make sure that any previous message has been handled
|
||||
mHandler.sendMessage(mHandler.obtainMessage(-1));
|
||||
waitForIdleHandler(mHandler, WAIT_TIMEOUT);
|
||||
HandlerUtilsKt.waitForIdle(mHandler, WAIT_TIMEOUT);
|
||||
}
|
||||
|
||||
static class LatchedHandler extends Handler {
|
||||
|
||||
Reference in New Issue
Block a user