@@ -2345,8 +2345,9 @@ protected static SecureRandom secureRandomFips(final byte[] seed) throws NoSuchA
23452345 * complete are a big drag on CI times which slows everyone down.
23462346 * <p>
23472347 * For instance, tests which verify things that require the passage of time ought to simulate this (e.g. using a {@link
2348- * org.elasticsearch.common.util.concurrent.DeterministicTaskQueue}). Excessive busy-waits ought to be replaced by blocking waits (e.g.
2349- * using a {@link CountDownLatch}) which release as soon as the condition is satisfied.
2348+ * org.elasticsearch.common.util.concurrent.DeterministicTaskQueue}). Excessive busy-waits ought to be replaced by blocking waits. For
2349+ * instance, use a {@link CountDownLatch} or {@link CyclicBarrier} or similar to continue execution as soon as a condition is satisfied.
2350+ * To wait for a particular cluster state, use {@link ClusterServiceUtils#addTemporaryStateListener} rather than busy-waiting on an API.
23502351 */
23512352 public static final TimeValue SAFE_AWAIT_TIMEOUT = TimeValue .timeValueSeconds (10 );
23522353
@@ -2424,7 +2425,7 @@ public static void safeAcquire(int permits, Semaphore semaphore) {
24242425 * @return The value with which the {@code listener} was completed.
24252426 */
24262427 public static <T > T safeAwait (SubscribableListener <T > listener ) {
2427- return safeAwait (listener , SAFE_AWAIT_TIMEOUT . getMillis (), TimeUnit . MILLISECONDS );
2428+ return safeAwait (listener , SAFE_AWAIT_TIMEOUT );
24282429 }
24292430
24302431 /**
@@ -2433,10 +2434,10 @@ public static <T> T safeAwait(SubscribableListener<T> listener) {
24332434 *
24342435 * @return The value with which the {@code listener} was completed.
24352436 */
2436- public static <T > T safeAwait (SubscribableListener <T > listener , long timeout , TimeUnit unit ) {
2437+ public static <T > T safeAwait (SubscribableListener <T > listener , TimeValue timeout ) {
24372438 final var future = new TestPlainActionFuture <T >();
24382439 listener .addListener (future );
2439- return safeGet (future , timeout , unit );
2440+ return safeGet (future , timeout );
24402441 }
24412442
24422443 /**
@@ -2466,7 +2467,7 @@ public static <T extends ActionResponse> T safeExecute(ElasticsearchClient clien
24662467 * @return The value with which the {@code future} was completed.
24672468 */
24682469 public static <T > T safeGet (Future <T > future ) {
2469- return safeGet (future , SAFE_AWAIT_TIMEOUT . millis (), TimeUnit . MILLISECONDS );
2470+ return safeGet (future , SAFE_AWAIT_TIMEOUT );
24702471 }
24712472
24722473 /**
@@ -2475,9 +2476,10 @@ public static <T> T safeGet(Future<T> future) {
24752476 *
24762477 * @return The value with which the {@code future} was completed.
24772478 */
2478- public static <T > T safeGet (Future <T > future , long timeout , TimeUnit unit ) {
2479+ // NB private because tests should be designed not to need to wait for longer than SAFE_AWAIT_TIMEOUT.
2480+ private static <T > T safeGet (Future <T > future , TimeValue timeout ) {
24792481 try {
2480- return future .get (timeout , unit );
2482+ return future .get (timeout . millis (), TimeUnit . MILLISECONDS );
24812483 } catch (InterruptedException e ) {
24822484 Thread .currentThread ().interrupt ();
24832485 throw new AssertionError ("safeGet: interrupted waiting for SubscribableListener" , e );
0 commit comments