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

Commit 675274fa authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN
Browse files

Fix IpReachabilityMonitorTest flakes/Q failures

IpReachabilityMonitor was failing on Q because of:
 - Usage of HexEncoding.encodeToString(byte[], boolean) that did not
   exist in Q
 - Flakes/failures caused by missing permissions when calling
   IpConnectivityLog
 - Flakes caused by mocking FileDescriptor#valid() while it could be
   accessed from another thread

Bug: 152723363
Test: atest IpReachabilityMonitorTest --rerun-until-failure 500
Merged-In: I9d38c696bf1b3b63be3b9df3161168ee291e7beb
Change-Id: I9d38c696bf1b3b63be3b9df3161168ee291e7beb
(cherry picked from commit 162c7ee3)
parent 5f3bb6d0
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@ public class IpReachabilityMonitor {
    private final Dependencies mDependencies;
    private final boolean mUsingMultinetworkPolicyTracker;
    private final ConnectivityManager mCm;
    private final IpConnectivityLog mMetricsLog = new IpConnectivityLog();
    private final IpConnectivityLog mMetricsLog;
    private final Context mContext;
    private final INetd mNetd;
    private LinkProperties mLinkProperties = new LinkProperties();
@@ -201,13 +201,13 @@ public class IpReachabilityMonitor {
            Context context, InterfaceParams ifParams, Handler h, SharedLog log, Callback callback,
            boolean usingMultinetworkPolicyTracker, final INetd netd) {
        this(context, ifParams, h, log, callback, usingMultinetworkPolicyTracker,
                Dependencies.makeDefault(context, ifParams.name), netd);
                Dependencies.makeDefault(context, ifParams.name), new IpConnectivityLog(), netd);
    }

    @VisibleForTesting
    IpReachabilityMonitor(Context context, InterfaceParams ifParams, Handler h, SharedLog log,
            Callback callback, boolean usingMultinetworkPolicyTracker, Dependencies dependencies,
            final INetd netd) {
            final IpConnectivityLog metricsLog, final INetd netd) {
        if (ifParams == null) throw new IllegalArgumentException("null InterfaceParams");

        mContext = context;
@@ -217,6 +217,7 @@ public class IpReachabilityMonitor {
        mUsingMultinetworkPolicyTracker = usingMultinetworkPolicyTracker;
        mCm = context.getSystemService(ConnectivityManager.class);
        mDependencies = dependencies;
        mMetricsLog = metricsLog;
        mNetd = netd;
        Preconditions.checkNotNull(mNetd);
        Preconditions.checkArgument(!TextUtils.isEmpty(mInterfaceParams.name));
+6 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.net.IpPrefix
import android.net.LinkAddress
import android.net.LinkProperties
import android.net.RouteInfo
import android.net.metrics.IpConnectivityLog
import android.net.netlink.StructNdMsg.NUD_FAILED
import android.net.netlink.StructNdMsg.NUD_STALE
import android.net.netlink.makeNewNeighMessage
@@ -35,6 +36,7 @@ import android.system.ErrnoException
import android.system.OsConstants.EAGAIN
import androidx.test.filters.SmallTest
import androidx.test.runner.AndroidJUnit4
import com.android.testutils.waitForIdle
import org.junit.After
import org.junit.Before
import org.junit.Test
@@ -102,6 +104,7 @@ class IpReachabilityMonitorTest {
    private val context = mock(Context::class.java)
    private val netd = mock(INetd::class.java)
    private val fd = mock(FileDescriptor::class.java)
    private val metricsLog = mock(IpConnectivityLog::class.java)

    private val handlerThread = HandlerThread(IpReachabilityMonitorTest::class.simpleName)
    private val handler by lazy { Handler(handlerThread.looper) }
@@ -181,6 +184,7 @@ class IpReachabilityMonitorTest {
                    callback,
                    false /* useMultinetworkPolicyTracker */,
                    dependencies,
                    metricsLog,
                    netd))
        }
        reachabilityMonitor = monitorFuture.get(TEST_TIMEOUT_MS, TimeUnit.MILLISECONDS)
@@ -190,6 +194,8 @@ class IpReachabilityMonitorTest {

    @After
    fun tearDown() {
        // Ensure the handler thread is not accessing the fd while changing its mock
        handlerThread.waitForIdle(TEST_TIMEOUT_MS)
        doReturn(false).`when`(fd).valid()
        handlerThread.quitSafely()
    }
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ private fun makeNeighborMessage(
    (if (neighAddr is Inet6Address) "1400" else "0800") +
    "0100" +             // type (1 == NDA_DST, for neighbor messages)
                         // IP address:
    encodeToString(neighAddr.address, false /* upperCase */) +
    encodeToString(neighAddr.address) +
    // -- struct nlattr: NDA_LLADDR --
    "0a00" +             // length = 10
    "0200" +             // type (2 == NDA_LLADDR, for neighbor messages)