@@ -2398,8 +2398,9 @@ protected static SecureRandom secureRandomFips(final byte[] seed) throws NoSuchA
2398
2398
* complete are a big drag on CI times which slows everyone down.
2399
2399
* <p>
2400
2400
* 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.
2403
2404
*/
2404
2405
public static final TimeValue SAFE_AWAIT_TIMEOUT = TimeValue .timeValueSeconds (10 );
2405
2406
@@ -2477,7 +2478,7 @@ public static void safeAcquire(int permits, Semaphore semaphore) {
2477
2478
* @return The value with which the {@code listener} was completed.
2478
2479
*/
2479
2480
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 );
2481
2482
}
2482
2483
2483
2484
/**
@@ -2486,10 +2487,10 @@ public static <T> T safeAwait(SubscribableListener<T> listener) {
2486
2487
*
2487
2488
* @return The value with which the {@code listener} was completed.
2488
2489
*/
2489
- public static <T > T safeAwait (SubscribableListener <T > listener , long timeout , TimeUnit unit ) {
2490
+ public static <T > T safeAwait (SubscribableListener <T > listener , TimeValue timeout ) {
2490
2491
final var future = new TestPlainActionFuture <T >();
2491
2492
listener .addListener (future );
2492
- return safeGet (future , timeout , unit );
2493
+ return safeGet (future , timeout );
2493
2494
}
2494
2495
2495
2496
/**
@@ -2519,7 +2520,7 @@ public static <T extends ActionResponse> T safeExecute(ElasticsearchClient clien
2519
2520
* @return The value with which the {@code future} was completed.
2520
2521
*/
2521
2522
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 );
2523
2524
}
2524
2525
2525
2526
/**
@@ -2528,9 +2529,10 @@ public static <T> T safeGet(Future<T> future) {
2528
2529
*
2529
2530
* @return The value with which the {@code future} was completed.
2530
2531
*/
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 ) {
2532
2534
try {
2533
- return future .get (timeout , unit );
2535
+ return future .get (timeout . millis (), TimeUnit . MILLISECONDS );
2534
2536
} catch (InterruptedException e ) {
2535
2537
Thread .currentThread ().interrupt ();
2536
2538
throw new AssertionError ("safeGet: interrupted waiting for SubscribableListener" , e );
0 commit comments