@@ -2398,8 +2398,9 @@ protected static SecureRandom secureRandomFips(final byte[] seed) throws NoSuchA
23982398 * complete are a big drag on CI times which slows everyone down.
23992399 * <p>
24002400 * For instance, tests which verify things that require the passage of time ought to simulate this (e.g. using a {@link
2401- * org.elasticsearch.common.util.concurrent.DeterministicTaskQueue}). Excessive busy-waits ought to be replaced by blocking waits (e.g.
2402- * using a {@link CountDownLatch}) which release as soon as the condition is satisfied.
2401+ * org.elasticsearch.common.util.concurrent.DeterministicTaskQueue}). Excessive busy-waits ought to be replaced by blocking waits. For
2402+ * instance, use a {@link CountDownLatch} or {@link CyclicBarrier} or similar to continue execution as soon as a condition is satisfied.
2403+ * To wait for a particular cluster state, use {@link ClusterServiceUtils#addTemporaryStateListener} rather than busy-waiting on an API.
24032404 */
24042405 public static final TimeValue SAFE_AWAIT_TIMEOUT = TimeValue .timeValueSeconds (10 );
24052406
@@ -2477,7 +2478,7 @@ public static void safeAcquire(int permits, Semaphore semaphore) {
24772478 * @return The value with which the {@code listener} was completed.
24782479 */
24792480 public static <T > T safeAwait (SubscribableListener <T > listener ) {
2480- return safeAwait (listener , SAFE_AWAIT_TIMEOUT . getMillis (), TimeUnit . MILLISECONDS );
2481+ return safeAwait (listener , SAFE_AWAIT_TIMEOUT );
24812482 }
24822483
24832484 /**
@@ -2486,10 +2487,10 @@ public static <T> T safeAwait(SubscribableListener<T> listener) {
24862487 *
24872488 * @return The value with which the {@code listener} was completed.
24882489 */
2489- public static <T > T safeAwait (SubscribableListener <T > listener , long timeout , TimeUnit unit ) {
2490+ public static <T > T safeAwait (SubscribableListener <T > listener , TimeValue timeout ) {
24902491 final var future = new TestPlainActionFuture <T >();
24912492 listener .addListener (future );
2492- return safeGet (future , timeout , unit );
2493+ return safeGet (future , timeout );
24932494 }
24942495
24952496 /**
@@ -2519,7 +2520,7 @@ public static <T extends ActionResponse> T safeExecute(ElasticsearchClient clien
25192520 * @return The value with which the {@code future} was completed.
25202521 */
25212522 public static <T > T safeGet (Future <T > future ) {
2522- return safeGet (future , SAFE_AWAIT_TIMEOUT . millis (), TimeUnit . MILLISECONDS );
2523+ return safeGet (future , SAFE_AWAIT_TIMEOUT );
25232524 }
25242525
25252526 /**
@@ -2528,9 +2529,10 @@ public static <T> T safeGet(Future<T> future) {
25282529 *
25292530 * @return The value with which the {@code future} was completed.
25302531 */
2531- public static <T > T safeGet (Future <T > future , long timeout , TimeUnit unit ) {
2532+ // NB private because tests should be designed not to need to wait for longer than SAFE_AWAIT_TIMEOUT.
2533+ private static <T > T safeGet (Future <T > future , TimeValue timeout ) {
25322534 try {
2533- return future .get (timeout , unit );
2535+ return future .get (timeout . millis (), TimeUnit . MILLISECONDS );
25342536 } catch (InterruptedException e ) {
25352537 Thread .currentThread ().interrupt ();
25362538 throw new AssertionError ("safeGet: interrupted waiting for SubscribableListener" , e );
0 commit comments