Skip to content

Commit

Permalink
[TEST] Make testNotReadyOnBadFileSettings more reliable (#93058) (#93092
Browse files Browse the repository at this point in the history
)

Co-authored-by: David Turner <david.turner@elastic.co>

Co-authored-by: David Turner <david.turner@elastic.co>
  • Loading branch information
grcevski and DaveCTurner committed Jan 19, 2023
1 parent 45cca3c commit a4de4db
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
*/
package org.elasticsearch.readiness;

import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateListener;
import org.elasticsearch.cluster.ClusterStateUpdateTask;
import org.elasticsearch.cluster.metadata.ReservedStateErrorMetadata;
import org.elasticsearch.cluster.metadata.ReservedStateHandlerMetadata;
import org.elasticsearch.cluster.metadata.ReservedStateMetadata;
Expand Down Expand Up @@ -258,6 +261,10 @@ public void testNotReadyOnBadFileSettings() throws Exception {
assertMasterNode(internalCluster().nonMasterClient(), masterNode);
var savedClusterState = setupClusterStateListenerForError(masterNode);

// we need this after we setup the listener above, in case the node started and processed
// settings before we set our listener to cluster state changes.
causeClusterStateUpdate();

FileSettingsService masterFileSettingsService = internalCluster().getInstance(FileSettingsService.class, masterNode);

assertTrue(masterFileSettingsService.watching());
Expand Down Expand Up @@ -319,4 +326,26 @@ public void testReadyAfterCorrectFileSettings() throws Exception {
ReadinessService s = internalCluster().getInstance(ReadinessService.class, internalCluster().getMasterName());
tcpReadinessProbeTrue(s);
}

private void causeClusterStateUpdate() {
PlainActionFuture.get(
fut -> internalCluster().getCurrentMasterNodeInstance(ClusterService.class)
.submitUnbatchedStateUpdateTask("poke", new ClusterStateUpdateTask() {
@Override
public ClusterState execute(ClusterState currentState) {
return ClusterState.builder(currentState).build();
}

@Override
public void onFailure(Exception e) {
assert false : e;
}

@Override
public void clusterStateProcessed(ClusterState initialState, ClusterState newState) {
fut.onResponse(null);
}
})
);
}
}

0 comments on commit a4de4db

Please sign in to comment.