Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd919747 authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

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
Change-Id: I32f24ed03fde6fe7e0d0531fa2a289b7f4f88745
parent 58da4e39
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -445,6 +445,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 boolean packetContainsExpectedField(final byte[] packet, final int offset,
@@ -1302,17 +1317,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()
@@ -1383,8 +1397,6 @@ public class IpClientIntegrationTest {
    public void testPref64Option() throws Exception {
        assumeTrue(ConstantsShim.VERSION > Build.VERSION_CODES.Q);

        disableRouterSolicitationDelay();

        ProvisioningConfiguration config = new ProvisioningConfiguration.Builder()
                .withoutIpReachabilityMonitor()
                .withoutIPv4()
@@ -1506,8 +1518,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();