diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2020-04-25 10:13:33 +0000 |
---|---|---|
committer | Lorenzo Colitti <lorenzo@google.com> | 2020-04-25 11:35:08 +0000 |
commit | 23013b08caa51f26606ad7b90c321b243e7c5e83 (patch) | |
tree | 8cdfd21508364dcdae0c60342475d94fe70f1953 | |
parent | 2ed62241f6433d0b4014f35157e7f2f17231637c (diff) |
Speed up IpClientIntegrationTest.
1. Ensure the IpMemoryStore always immediately answers questions
from the DHCP client. Otherwise, starting the DHCP client
takes two seconds as the query to the IpMemoryStore times out.
This does not affect tests that use the IpMemoryStore because
unlike when(), doAnswer() can be called multiple times.
2. Disable IPv6 provisioning delays before every test, instead of
requiring every test to do it individually.
3. Disable DAD as well as setting router solicitation delay to 0.
This results in the IP stack essentially immediately after
IpClient is told to start.
This speeds up the test by about 2x. Before:
$ time atest -ti NetworkStackIntegrationTests:IpClientIntegrationTest
...
real 1m21.375s
After:
$ time atest -ti NetworkStackIntegrationTests:IpClientIntegrationTest
...
real 0m41.642s
Bug: 152723363
Test: test-only change
Original-Change: http://aosp/1295486
Merged-In: I32f24ed03fde6fe7e0d0531fa2a289b7f4f88745
Change-Id: I32f24ed03fde6fe7e0d0531fa2a289b7f4f88745
-rw-r--r-- | tests/integration/src/android/net/ip/IpClientIntegrationTest.java | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/tests/integration/src/android/net/ip/IpClientIntegrationTest.java b/tests/integration/src/android/net/ip/IpClientIntegrationTest.java index 79264a8..5ae4470 100644 --- a/tests/integration/src/android/net/ip/IpClientIntegrationTest.java +++ b/tests/integration/src/android/net/ip/IpClientIntegrationTest.java @@ -449,6 +449,21 @@ public class IpClientIntegrationTest { mNetworkObserverRegistry.register(mNetd); mIpc = new IpClient(mContext, mIfaceName, mCb, mNetworkObserverRegistry, mNetworkStackServiceManager, mDependencies); + + // Tell the IpMemoryStore immediately to answer any question about network attributes with a + // null response. Otherwise, the DHCP client will wait for two seconds before starting, + // while its query to the IpMemoryStore times out. + // This does not affect any test that makes the mock memory store return results, because + // unlike when(), it is documented that doAnswer() can be called more than once, to change + // the behaviour of a mock in the middle of a test. + doAnswer(invocation -> { + final String l2Key = invocation.getArgument(0); + ((OnNetworkAttributesRetrievedListener) invocation.getArgument(1)) + .onNetworkAttributesRetrieved(new Status(SUCCESS), l2Key, null); + return null; + }).when(mIpMemoryStore).retrieveNetworkAttributes(any(), any()); + + disableIpv6ProvisioningDelays(); } private void expectAlarmCancelled(InOrder inOrder, OnAlarmListener listener) { @@ -1328,17 +1343,16 @@ public class IpClientIntegrationTest { return packet; } - private void disableRouterSolicitationDelay() throws Exception { - // Speed up the test by removing router_solicitation_delay. + private void disableIpv6ProvisioningDelays() throws Exception { + // Speed up the test by disabling DAD and removing router_solicitation_delay. // We don't need to restore the default value because the interface is removed in tearDown. - // TODO: speed up further by not waiting for RA but keying off first IPv6 packet. + // TODO: speed up further by not waiting for RS but keying off first IPv6 packet. mNetd.setProcSysNet(INetd.IPV6, INetd.CONF, mIfaceName, "router_solicitation_delay", "0"); + mNetd.setProcSysNet(INetd.IPV6, INetd.CONF, mIfaceName, "dad_transmits", "0"); } @Test public void testRaRdnss() throws Exception { - disableRouterSolicitationDelay(); - ProvisioningConfiguration config = new ProvisioningConfiguration.Builder() .withoutIpReachabilityMonitor() .withoutIPv4() @@ -1407,8 +1421,6 @@ public class IpClientIntegrationTest { public void testPref64Option() throws Exception { assumeTrue(ConstantsShim.VERSION > Build.VERSION_CODES.Q); - disableRouterSolicitationDelay(); - ProvisioningConfiguration config = new ProvisioningConfiguration.Builder() .withoutIpReachabilityMonitor() .withoutIPv4() @@ -1563,8 +1575,6 @@ public class IpClientIntegrationTest { // may be sufficient to call waitForIdle to see if IpClient has seen the address. addIpAddressAndWaitForIt(mIfaceName); - disableRouterSolicitationDelay(); - ProvisioningConfiguration config = new ProvisioningConfiguration.Builder() .withoutIpReachabilityMonitor() .build(); |