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

Commit 097a6d2e authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Make IpClientIntegrationTest pass on rvc-dev.

On rvc-dev, IpClientIntegrationTest fails almost all the time
because the tap interface disappears before the tests can run.
This is due to the ParcelFileDescriptor finalizer, which
helpfully closes the fd stored in the object even if it is in
use elsewhere.

Stash the ParcelFileDescriptor itself in the test class, instead
of the actual FileDescriptor which everything uses, in order to
ensure that the garbage collector does not finalize it.

With this change, IpClientIntegrationTest#testRaRdnss (just an
arbitrary test case in that class) goes from 10/10 failures to
10/10 passes.

Bug: 152723363
Test: atest NetworkStackNextIntegrationTests:IpClientIntegrationTest#testRaRdnss
Change-Id: I1015e7893ba6af74876665826960e8fcc1711476
parent f2799b4c
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -407,7 +407,13 @@ public class IpClientIntegrationTest {
        mPacketReaderThread.start();
        mHandler = mPacketReaderThread.getThreadHandler();

        mTapFd = iface.getFileDescriptor().getFileDescriptor();
        // Detach the FileDescriptor from the ParcelFileDescriptor.
        // Otherwise, the garbage collector might call the ParcelFileDescriptor's finalizer, which
        // closes the FileDescriptor and destroys our tap interface. An alternative would be to
        // make the ParcelFileDescriptor or the TestNetworkInterface a class member so they never
        // go out of scope.
        mTapFd = new FileDescriptor();
        mTapFd.setInt$(iface.getFileDescriptor().detachFd());
        mPacketReader = new TapPacketReader(mHandler, mTapFd, DATA_BUFFER_LEN);
        mHandler.post(() -> mPacketReader.start());
    }