From 236e0f3011574a7ca348dccc8cb0677e72ba6ace Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Thu, 17 Oct 2019 21:51:38 +0200 Subject: [PATCH] Speed up and reenable test for b/141603906 Test time goes from 90s on blueline down to 23s by multithreading and reducing the number of iterations. Test: InetDiagSocketTest Change-Id: I2dec7de80c0b731e64a8328ba01c4ed7fb198240 --- .../net/netlink/InetDiagSocketTest.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/net/java/android/net/netlink/InetDiagSocketTest.java b/tests/net/java/android/net/netlink/InetDiagSocketTest.java index 46e27c1d3d3b6..62add30639b05 100644 --- a/tests/net/java/android/net/netlink/InetDiagSocketTest.java +++ b/tests/net/java/android/net/netlink/InetDiagSocketTest.java @@ -45,7 +45,6 @@ import androidx.test.runner.AndroidJUnit4; import libcore.util.HexEncoding; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -201,14 +200,29 @@ public class InetDiagSocketTest { checkGetConnectionOwnerUid("::1", "::1"); } - @Ignore("Times out on Marlin/Sailfish") /* Verify fix for b/141603906 */ @Test public void testB141603906() throws Exception { final InetSocketAddress src = new InetSocketAddress(0); final InetSocketAddress dst = new InetSocketAddress(0); - for (int i = 1; i <= 100000; i++) { - mCm.getConnectionOwnerUid(IPPROTO_TCP, src, dst); + final int numThreads = 8; + final int numSockets = 5000; + final Thread[] threads = new Thread[numThreads]; + + for (int i = 0; i < numThreads; i++) { + threads[i] = new Thread(() -> { + for (int j = 0; j < numSockets; j++) { + mCm.getConnectionOwnerUid(IPPROTO_TCP, src, dst); + } + }); + } + + for (Thread thread : threads) { + thread.start(); + } + + for (Thread thread : threads) { + thread.join(); } }