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

Commit 87b5dd44 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN
Browse files

Wait for IpClient.StoppedState#enter before tests

IpClientIntegrationTest is flaky because some mocks that IpClient uses,
like mNetd, can be stubbed while IpClient is initializing in its handler
thread. This generates UnfinishedStubbingExceptions as IpClient is
calling methods on the mock while the test is trying to stub additional
methods.

Wait for IpClient to become idle before doing any further setup.

Bug: 152723363
Test: atest NetworkStackCoverageTests:IpClientIntegrationTests
          --rerun-until-failure [lots] on Q Cuttlefish
Original-Change: https://android-review.googlesource.com/1298472
Merged-In: I90206a16fff1fa12ca7e37e36d49163b6a83e5c1
Change-Id: I90206a16fff1fa12ca7e37e36d49163b6a83e5c1
parent 2e16ff33
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -449,6 +449,11 @@ public class IpClientIntegrationTest {
        mNetworkObserverRegistry.register(mNetd);
        mIpc = new IpClient(mContext, mIfaceName, mCb, mNetworkObserverRegistry,
                mNetworkStackServiceManager, mDependencies);
        // Wait for IpClient to enter its initial state. Otherwise, additional setup steps or tests
        // that mock IpClient's dependencies might interact with those mocks while IpClient is
        // starting. This would cause UnfinishedStubbingExceptions as mocks cannot be interacted
        // with while they are being stubbed.
        HandlerUtilsKt.waitForIdle(mIpc.getHandler(), TEST_TIMEOUT_MS);

        // 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,