summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author junyulai <junyulai@google.com> 2019-03-19 18:50:23 +0800
committer Junyu Lai <junyulai@google.com> 2019-03-25 12:56:47 +0000
commitafe9b49f0ba2c617dec23d21cdf3871ef8c5fd6c (patch)
treef8a9d87f42648b4dc41c15c85663c457495c601f
parent8324c3e7e55c77fae5ca7785d99bd094a7ef49f4 (diff)
Reveal the call trace of failed test cases which run in executors
Currently, the fails in testTcpSocketKeepalives are triggered by fail() inside the executor, which is hiding the actual call trace but only message remains. And it made the fail case hard to debug. So this commit is to bubble up the Exception by using a custom functional interface. Bug: 123987272 Test: 1. atest FrameworksNetTests 2. manually fail the test case and see the call trace Change-Id: I125e673938a5e9d1de86f83c1a732227a4bd3207
-rw-r--r--tests/net/java/com/android/server/ConnectivityServiceTest.java30
1 files changed, 11 insertions, 19 deletions
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index 92a865a3dc58..bda2cb6c6f98 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -212,7 +212,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.function.Consumer;
import java.util.function.Predicate;
/**
@@ -4022,8 +4021,13 @@ public class ConnectivityServiceTest {
callback3.expectStopped();
}
+ @FunctionalInterface
+ private interface ThrowingConsumer<T> {
+ void accept(T t) throws Exception;
+ }
+
// Helper method to prepare the executor and run test
- private void runTestWithSerialExecutors(Consumer<Executor> functor) {
+ private void runTestWithSerialExecutors(ThrowingConsumer<Executor> functor) throws Exception {
final ExecutorService executorSingleThread = Executors.newSingleThreadExecutor();
final Executor executorInline = (Runnable r) -> r.run();
functor.accept(executorSingleThread);
@@ -4032,15 +4036,9 @@ public class ConnectivityServiceTest {
}
@Test
- public void testNattSocketKeepalives() {
- runTestWithSerialExecutors(executor -> {
- try {
- doTestNattSocketKeepalivesWithExecutor(executor);
- doTestNattSocketKeepalivesFdWithExecutor(executor);
- } catch (Exception e) {
- fail(e.getMessage());
- }
- });
+ public void testNattSocketKeepalives() throws Exception {
+ runTestWithSerialExecutors(executor -> doTestNattSocketKeepalivesWithExecutor(executor));
+ runTestWithSerialExecutors(executor -> doTestNattSocketKeepalivesFdWithExecutor(executor));
}
private void doTestNattSocketKeepalivesWithExecutor(Executor executor) throws Exception {
@@ -4210,14 +4208,8 @@ public class ConnectivityServiceTest {
}
@Test
- public void testTcpSocketKeepalives() {
- runTestWithSerialExecutors(executor -> {
- try {
- doTestTcpSocketKeepalivesWithExecutor(executor);
- } catch (Exception e) {
- fail(e.getMessage());
- }
- });
+ public void testTcpSocketKeepalives() throws Exception {
+ runTestWithSerialExecutors(executor -> doTestTcpSocketKeepalivesWithExecutor(executor));
}
private void doTestTcpSocketKeepalivesWithExecutor(Executor executor) throws Exception {