Increase linger delay and test callback timeout

Tests appear to have become much slower on apct in recent runs, although
local runs do not seem to be affected. As a first measure, increase our
timeouts to eliminate flakyness.

Bug: b/111778226
Test: runtest --no-hidden-api-checks -x ConnectivityServiceTest.java
Change-Id: I7a3bfb646eb554bcd9d50d026142f2a2cff74beb
This commit is contained in:
Remi NGUYEN VAN
2018-07-26 16:39:45 +09:00
parent 50cb7dbc11
commit b6bd15ac29

View File

@@ -62,9 +62,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.any; import static org.mockito.Mockito.any;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq;
@@ -85,7 +83,6 @@ import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.UserInfo;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.CaptivePortal; import android.net.CaptivePortal;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
@@ -114,7 +111,6 @@ import android.net.NetworkUtils;
import android.net.RouteInfo; import android.net.RouteInfo;
import android.net.StringNetworkSpecifier; import android.net.StringNetworkSpecifier;
import android.net.UidRange; import android.net.UidRange;
import android.net.VpnService;
import android.net.captiveportal.CaptivePortalProbeResult; import android.net.captiveportal.CaptivePortalProbeResult;
import android.net.metrics.IpConnectivityLog; import android.net.metrics.IpConnectivityLog;
import android.net.util.MultinetworkPolicyTracker; import android.net.util.MultinetworkPolicyTracker;
@@ -135,7 +131,6 @@ import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import android.test.mock.MockContentResolver; import android.test.mock.MockContentResolver;
import android.text.TextUtils;
import android.util.ArraySet; import android.util.ArraySet;
import android.util.Log; import android.util.Log;
@@ -196,7 +191,13 @@ public class ConnectivityServiceTest {
private static final String TAG = "ConnectivityServiceTest"; private static final String TAG = "ConnectivityServiceTest";
private static final int TIMEOUT_MS = 500; private static final int TIMEOUT_MS = 500;
private static final int TEST_LINGER_DELAY_MS = 120; private static final int TEST_LINGER_DELAY_MS = 250;
// Chosen to be less than the linger timeout. This ensures that we can distinguish between a
// LOST callback that arrives immediately and a LOST callback that arrives after the linger
// timeout. For this, our assertions should run fast enough to leave less than
// (mService.mLingerDelayMs - TEST_CALLBACK_TIMEOUT_MS) between the time callbacks are
// supposedly fired, and the time we call expectCallback.
private final static int TEST_CALLBACK_TIMEOUT_MS = 200;
private static final String CLAT_PREFIX = "v4-"; private static final String CLAT_PREFIX = "v4-";
private static final String MOBILE_IFNAME = "test_rmnet_data0"; private static final String MOBILE_IFNAME = "test_rmnet_data0";
@@ -1463,13 +1464,6 @@ public class ConnectivityServiceTest {
* received. assertNoCallback may be called at any time. * received. assertNoCallback may be called at any time.
*/ */
private class TestNetworkCallback extends NetworkCallback { private class TestNetworkCallback extends NetworkCallback {
// Chosen to be less than the linger timeout. This ensures that we can distinguish
// between a LOST callback that arrives immediately and a LOST callback that arrives after
// the linger timeout. For this, our assertions should run fast enough to leave less than
// (mService.mLingerDelayMs - TIMEOUT_MS) between the time callbacks are supposedly fired,
// and the time we call expectCallback.
private final static int TIMEOUT_MS = 100;
private final LinkedBlockingQueue<CallbackInfo> mCallbacks = new LinkedBlockingQueue<>(); private final LinkedBlockingQueue<CallbackInfo> mCallbacks = new LinkedBlockingQueue<>();
private Network mLastAvailableNetwork; private Network mLastAvailableNetwork;
@@ -1554,11 +1548,11 @@ public class ConnectivityServiceTest {
} }
CallbackInfo expectCallback(CallbackState state, MockNetworkAgent agent) { CallbackInfo expectCallback(CallbackState state, MockNetworkAgent agent) {
return expectCallback(state, agent, TIMEOUT_MS); return expectCallback(state, agent, TEST_CALLBACK_TIMEOUT_MS);
} }
CallbackInfo expectCallbackLike(Predicate<CallbackInfo> fn) { CallbackInfo expectCallbackLike(Predicate<CallbackInfo> fn) {
return expectCallbackLike(fn, TIMEOUT_MS); return expectCallbackLike(fn, TEST_CALLBACK_TIMEOUT_MS);
} }
CallbackInfo expectCallbackLike(Predicate<CallbackInfo> fn, int timeoutMs) { CallbackInfo expectCallbackLike(Predicate<CallbackInfo> fn, int timeoutMs) {
@@ -1601,15 +1595,15 @@ public class ConnectivityServiceTest {
// Expects the available callbacks (validated), plus onSuspended. // Expects the available callbacks (validated), plus onSuspended.
void expectAvailableAndSuspendedCallbacks(MockNetworkAgent agent, boolean expectValidated) { void expectAvailableAndSuspendedCallbacks(MockNetworkAgent agent, boolean expectValidated) {
expectAvailableCallbacks(agent, true, expectValidated, TIMEOUT_MS); expectAvailableCallbacks(agent, true, expectValidated, TEST_CALLBACK_TIMEOUT_MS);
} }
void expectAvailableCallbacksValidated(MockNetworkAgent agent) { void expectAvailableCallbacksValidated(MockNetworkAgent agent) {
expectAvailableCallbacks(agent, false, true, TIMEOUT_MS); expectAvailableCallbacks(agent, false, true, TEST_CALLBACK_TIMEOUT_MS);
} }
void expectAvailableCallbacksUnvalidated(MockNetworkAgent agent) { void expectAvailableCallbacksUnvalidated(MockNetworkAgent agent) {
expectAvailableCallbacks(agent, false, false, TIMEOUT_MS); expectAvailableCallbacks(agent, false, false, TEST_CALLBACK_TIMEOUT_MS);
} }
// Expects the available callbacks (where the onCapabilitiesChanged must contain the // Expects the available callbacks (where the onCapabilitiesChanged must contain the
@@ -1617,9 +1611,9 @@ public class ConnectivityServiceTest {
// one we just sent. // one we just sent.
// TODO: this is likely a bug. Fix it and remove this method. // TODO: this is likely a bug. Fix it and remove this method.
void expectAvailableDoubleValidatedCallbacks(MockNetworkAgent agent) { void expectAvailableDoubleValidatedCallbacks(MockNetworkAgent agent) {
expectCallback(CallbackState.AVAILABLE, agent, TIMEOUT_MS); expectCallback(CallbackState.AVAILABLE, agent, TEST_CALLBACK_TIMEOUT_MS);
NetworkCapabilities nc1 = expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, agent); NetworkCapabilities nc1 = expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, agent);
expectCallback(CallbackState.LINK_PROPERTIES, agent, TIMEOUT_MS); expectCallback(CallbackState.LINK_PROPERTIES, agent, TEST_CALLBACK_TIMEOUT_MS);
NetworkCapabilities nc2 = expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, agent); NetworkCapabilities nc2 = expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, agent);
assertEquals(nc1, nc2); assertEquals(nc1, nc2);
} }
@@ -1633,7 +1627,7 @@ public class ConnectivityServiceTest {
} }
NetworkCapabilities expectCapabilitiesWith(int capability, MockNetworkAgent agent) { NetworkCapabilities expectCapabilitiesWith(int capability, MockNetworkAgent agent) {
return expectCapabilitiesWith(capability, agent, TIMEOUT_MS); return expectCapabilitiesWith(capability, agent, TEST_CALLBACK_TIMEOUT_MS);
} }
NetworkCapabilities expectCapabilitiesWith(int capability, MockNetworkAgent agent, NetworkCapabilities expectCapabilitiesWith(int capability, MockNetworkAgent agent,
@@ -1645,7 +1639,7 @@ public class ConnectivityServiceTest {
} }
NetworkCapabilities expectCapabilitiesWithout(int capability, MockNetworkAgent agent) { NetworkCapabilities expectCapabilitiesWithout(int capability, MockNetworkAgent agent) {
return expectCapabilitiesWithout(capability, agent, TIMEOUT_MS); return expectCapabilitiesWithout(capability, agent, TEST_CALLBACK_TIMEOUT_MS);
} }
NetworkCapabilities expectCapabilitiesWithout(int capability, MockNetworkAgent agent, NetworkCapabilities expectCapabilitiesWithout(int capability, MockNetworkAgent agent,