Skip to content

Commit 3a81213

Browse files
Test fix: align timeouts in testDataStreamLifecycleDownsampleRollingRestart (#123769) (#126682) (#127049)
Recently we changed the implementation of `testDataStreamLifecycleDownsampleRollingRestart` to use a temporary state listener. We missed that the listener also had a timeout that was quite shorter than the `safeGet` timeout we were configuring. In this PR we align these two timeouts. Fixes: #123769 (cherry picked from commit e461717) # Conflicts: # muted-tests.yml # x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/DataStreamLifecycleDownsampleDisruptionIT.java Co-authored-by: Mary Gouseti <[email protected]>
1 parent 09a5c67 commit 3a81213

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,23 @@ public void clusterStateProcessed(ClusterState initialState, ClusterState newSta
264264
}
265265

266266
public static SubscribableListener<Void> addTemporaryStateListener(ClusterService clusterService, Predicate<ClusterState> predicate) {
267+
return addTemporaryStateListener(clusterService, predicate, ESTestCase.SAFE_AWAIT_TIMEOUT);
268+
}
269+
270+
/**
271+
* Creates a {@link ClusterStateListener} which subscribes to the given {@link ClusterService} and waits for it to apply a cluster state
272+
* that satisfies {@code predicate}, at which point it unsubscribes itself.
273+
*
274+
* @return A {@link SubscribableListener} which is completed when the first cluster state matching {@code predicate} is applied by the
275+
* given {@code clusterService}. If the current cluster state already matches {@code predicate} then the returned listener is
276+
* already complete. If no matching cluster state is seen within the provided {@code timeout} then the listener is
277+
* completed exceptionally on the scheduler thread that belongs to {@code clusterService}.
278+
*/
279+
public static SubscribableListener<Void> addTemporaryStateListener(
280+
ClusterService clusterService,
281+
Predicate<ClusterState> predicate,
282+
TimeValue timeout
283+
) {
267284
final var listener = new SubscribableListener<Void>();
268285
final ClusterStateListener clusterStateListener = new ClusterStateListener() {
269286
@Override
@@ -287,7 +304,7 @@ public String toString() {
287304
if (predicate.test(clusterService.state())) {
288305
listener.onResponse(null);
289306
} else {
290-
listener.addTimeout(ESTestCase.SAFE_AWAIT_TIMEOUT, clusterService.threadPool(), EsExecutors.DIRECT_EXECUTOR_SERVICE);
307+
listener.addTimeout(timeout, clusterService.threadPool(), EsExecutors.DIRECT_EXECUTOR_SERVICE);
291308
}
292309
return listener;
293310
}

x-pack/plugin/downsample/src/internalClusterTest/java/org/elasticsearch/xpack/downsample/DataStreamLifecycleDownsampleDisruptionIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private void ensureDownsamplingStatus(String downsampledIndex, IndexMetadata.Dow
117117
return true;
118118
}
119119
return false;
120-
});
120+
}, timeout);
121121
safeAwait(listener, timeout.millis(), TimeUnit.MILLISECONDS);
122122
}
123123
}

0 commit comments

Comments
 (0)