Skip to content

Commit e5a37b0

Browse files
Fix test infra NPE in doEnsureClusterStateConsistency (#131859)
1 parent 46ce911 commit e5a37b0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,15 @@ private void setMultiProjectParams(Map<String, String> xContentParams) {
13821382
}
13831383
}
13841384

1385+
/**
1386+
* Verifies that all nodes in the cluster see the same master node and cluster UUID and use the same JSON serialization.
1387+
* <ul>
1388+
* <li> Fetches the cluster state from every node in the cluster </li>
1389+
* <li> Fetches the master node's view of the cluster state </li>
1390+
* <li> Compares each node's view with the master node's </li>
1391+
* </ul>
1392+
* @param namedWriteableRegistry
1393+
*/
13851394
protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry namedWriteableRegistry) {
13861395
// This check has very little value in external test clusters and there is no guaranteed method of obtaining the master cluster
13871396
// state in those clusters.
@@ -1409,6 +1418,10 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name
14091418
);
14101419
Map<String, Object> masterStateMap = convertToMap(masterClusterState, xContentParams());
14111420
String masterId = masterClusterState.nodes().getMasterNodeId();
1421+
if (masterId == null) {
1422+
logger.warn("Failed to find an elected master in the cluster state: " + masterClusterState);
1423+
throw new AssertionError("Unable to find master in cluster state. Expecting a stable master node");
1424+
}
14121425
for (SubscribableListener<ClusterStateResponse> localStateListener : localStates) {
14131426
localStateListener.andThenAccept(localClusterStateResponse -> {
14141427
byte[] localClusterStateBytes = ClusterState.Builder.toBytes(localClusterStateResponse.getState());

0 commit comments

Comments
 (0)