summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2020-04-18 06:22:08 +0000
committerLorenzo Colitti <lorenzo@google.com>2020-04-18 08:07:01 +0000
commit81542c5cb6c4216ea6a8b17b0f16694f0f740e46 (patch)
tree9f70a34c546df4d136c2d423bda4eaf78071a89d
parent4fc16c370a31c03a1bf58793688a97d5c86b3ba6 (diff)
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 Merged-In: I1015e7893ba6af74876665826960e8fcc1711476 Change-Id: I1015e7893ba6af74876665826960e8fcc1711476
-rw-r--r--tests/integration/src/android/net/ip/IpClientIntegrationTest.java8
1 files changed, 7 insertions, 1 deletions
diff --git a/tests/integration/src/android/net/ip/IpClientIntegrationTest.java b/tests/integration/src/android/net/ip/IpClientIntegrationTest.java
index 56ad6c1..fdeddca 100644
--- a/tests/integration/src/android/net/ip/IpClientIntegrationTest.java
+++ b/tests/integration/src/android/net/ip/IpClientIntegrationTest.java
@@ -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());
}