فهرست منبع

Remove exception-mangling in ESTestCase#safeAwait (#102670)

The static `PlainActionFuture#get` utility actually wraps up a call to
`PlainActionFuture#actionGet` which unwraps exceptions sometimes,
eliding useful information about the source of the problem. This commit
moves to using `Future#get`, with assertions that no exception is thrown
that capture the full stack trace always.
David Turner 1 سال پیش
والد
کامیت
9e83ebfc5d
1فایلهای تغییر یافته به همراه14 افزوده شده و 1 حذف شده
  1. 14 1
      test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

+ 14 - 1
test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

@@ -161,8 +161,10 @@ import java.util.TimeZone;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.BooleanSupplier;
 import java.util.function.Consumer;
@@ -2068,7 +2070,18 @@ public abstract class ESTestCase extends LuceneTestCase {
     }
 
     public static <T> T safeAwait(SubscribableListener<T> listener) {
-        return PlainActionFuture.get(listener::addListener, 10, TimeUnit.SECONDS);
+        final var future = new PlainActionFuture<T>();
+        listener.addListener(future);
+        try {
+            return future.get(10, TimeUnit.SECONDS);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            throw new AssertionError("safeAwait: interrupted", e);
+        } catch (ExecutionException e) {
+            throw new AssertionError("safeAwait: listener was completed exceptionally", e);
+        } catch (TimeoutException e) {
+            throw new AssertionError("safeAwait: listener was not completed within the timeout", e);
+        }
     }
 
     public static void safeSleep(long millis) {