Merge "Add a common test library."

This commit is contained in:
Chalard Jean
2019-05-29 12:16:08 +00:00
committed by Gerrit Code Review
5 changed files with 17 additions and 30 deletions

View File

@@ -10,6 +10,7 @@ java_defaults {
"framework-protos",
"androidx.test.rules",
"mockito-target-minus-junit4",
"net-tests-utils",
"platform-test-annotations",
"services.core",
"services.net",

View File

@@ -16,8 +16,6 @@
package android.net.nsd;
import static com.android.internal.util.TestUtils.waitForIdleHandler;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -40,6 +38,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.util.AsyncChannel;
import com.android.testutils.HandlerUtilsKt;
import org.junit.After;
import org.junit.Before;
@@ -74,7 +73,7 @@ public class NsdManagerTest {
@After
public void tearDown() throws Exception {
mServiceHandler.waitForIdle(mTimeoutMs);
HandlerUtilsKt.waitForIdle(mServiceHandler, mTimeoutMs);
mServiceHandler.chan.disconnect();
mServiceHandler.stop();
if (mManager != null) {
@@ -334,7 +333,7 @@ public class NsdManagerTest {
}
int verifyRequest(int expectedMessageType) {
mServiceHandler.waitForIdle(mTimeoutMs);
HandlerUtilsKt.waitForIdle(mServiceHandler, mTimeoutMs);
verify(mServiceHandler, timeout(mTimeoutMs)).handleMessage(any());
reset(mServiceHandler);
Message received = mServiceHandler.getLastMessage();
@@ -366,10 +365,6 @@ public class NsdManagerTest {
lastMessage.copyFrom(msg);
}
void waitForIdle(long timeoutMs) {
waitForIdleHandler(this, timeoutMs);
}
@Override
public void handleMessage(Message msg) {
setLastMessage(msg);

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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;
@@ -105,6 +104,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;
@@ -1321,8 +1321,6 @@ public class NetworkStatsServiceTest {
expectNetworkStatsSummary(buildEmptyStats());
expectNetworkStatsUidDetail(buildEmptyStats());
// Register and verify request and that binder was called
DataUsageRequest request =
mService.registerUsageCallback(mServiceContext.getOpPackageName(), inputRequest,
@@ -1334,14 +1332,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);
@@ -1674,7 +1669,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 {