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

Commit 614ab3dd authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by android-build-merger
Browse files

Merge "Fix flaky UdpEncapsulationSocket test" am: 13078345

am: ae9f7b67

Change-Id: Idf040a67e53d9b9ec6e6c647ce24f8ada501d355
parents 14d635ac ae9f7b67
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -96,9 +96,10 @@ public class IpSecService extends IIpSecService.Stub {
            new int[] {OsConstants.AF_INET, OsConstants.AF_INET6};

    private static final int NETD_FETCH_TIMEOUT_MS = 5000; // ms
    private static final int MAX_PORT_BIND_ATTEMPTS = 10;
    private static final InetAddress INADDR_ANY;

    @VisibleForTesting static final int MAX_PORT_BIND_ATTEMPTS = 10;

    static {
        try {
            INADDR_ANY = InetAddress.getByAddress(new byte[] {0, 0, 0, 0});
+20 −14
Original line number Diff line number Diff line
@@ -156,10 +156,21 @@ public class IpSecServiceTest {

    @Test
    public void testOpenAndCloseUdpEncapsulationSocket() throws Exception {
        int localport = findUnusedPort();
        int localport = -1;
        IpSecUdpEncapResponse udpEncapResp = null;

        for (int i = 0; i < IpSecService.MAX_PORT_BIND_ATTEMPTS; i++) {
            localport = findUnusedPort();

            udpEncapResp = mIpSecService.openUdpEncapsulationSocket(localport, new Binder());
            assertNotNull(udpEncapResp);
            if (udpEncapResp.status == IpSecManager.Status.OK) {
                break;
            }

            // Else retry to reduce possibility for port-bind failures.
        }

        IpSecUdpEncapResponse udpEncapResp =
                mIpSecService.openUdpEncapsulationSocket(localport, new Binder());
        assertNotNull(udpEncapResp);
        assertEquals(IpSecManager.Status.OK, udpEncapResp.status);
        assertEquals(localport, udpEncapResp.port);
@@ -204,12 +215,11 @@ public class IpSecServiceTest {

    @Test
    public void testOpenUdpEncapsulationSocketAfterClose() throws Exception {
        int localport = findUnusedPort();
        IpSecUdpEncapResponse udpEncapResp =
                mIpSecService.openUdpEncapsulationSocket(localport, new Binder());
                mIpSecService.openUdpEncapsulationSocket(0, new Binder());
        assertNotNull(udpEncapResp);
        assertEquals(IpSecManager.Status.OK, udpEncapResp.status);
        assertEquals(localport, udpEncapResp.port);
        int localport = udpEncapResp.port;

        mIpSecService.closeUdpEncapsulationSocket(udpEncapResp.resourceId);
        udpEncapResp.fileDescriptor.close();
@@ -226,12 +236,11 @@ public class IpSecServiceTest {
     */
    @Test
    public void testUdpEncapPortNotReleased() throws Exception {
        int localport = findUnusedPort();
        IpSecUdpEncapResponse udpEncapResp =
                mIpSecService.openUdpEncapsulationSocket(localport, new Binder());
                mIpSecService.openUdpEncapsulationSocket(0, new Binder());
        assertNotNull(udpEncapResp);
        assertEquals(IpSecManager.Status.OK, udpEncapResp.status);
        assertEquals(localport, udpEncapResp.port);
        int localport = udpEncapResp.port;

        udpEncapResp.fileDescriptor.close();

@@ -273,14 +282,11 @@ public class IpSecServiceTest {

    @Test
    public void testOpenUdpEncapsulationSocketTwice() throws Exception {
        int localport = findUnusedPort();

        IpSecUdpEncapResponse udpEncapResp =
                mIpSecService.openUdpEncapsulationSocket(localport, new Binder());
                mIpSecService.openUdpEncapsulationSocket(0, new Binder());
        assertNotNull(udpEncapResp);
        assertEquals(IpSecManager.Status.OK, udpEncapResp.status);
        assertEquals(localport, udpEncapResp.port);
        mIpSecService.openUdpEncapsulationSocket(localport, new Binder());
        int localport = udpEncapResp.port;

        IpSecUdpEncapResponse testUdpEncapResp =
                mIpSecService.openUdpEncapsulationSocket(localport, new Binder());