diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index 89099bb7e32ff..e3bb94748c58f 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -1381,6 +1381,15 @@ private void setMultiProjectParams(Map xContentParams) { } } + /** + * Verifies that all nodes in the cluster see the same master node and cluster UUID and use the same JSON serialization. + * + * @param namedWriteableRegistry + */ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry namedWriteableRegistry) { // This check has very little value in external test clusters and there is no guaranteed method of obtaining the master cluster // state in those clusters. @@ -1408,6 +1417,10 @@ protected final void doEnsureClusterStateConsistency(NamedWriteableRegistry name ); Map masterStateMap = convertToMap(masterClusterState, xContentParams()); String masterId = masterClusterState.nodes().getMasterNodeId(); + if (masterId == null) { + logger.warn("Failed to find an elected master in the cluster state: " + masterClusterState); + throw new AssertionError("Unable to find master in cluster state. Expecting a stable master node"); + } for (SubscribableListener localStateListener : localStates) { localStateListener.andThenAccept(localClusterStateResponse -> { byte[] localClusterStateBytes = ClusterState.Builder.toBytes(localClusterStateResponse.getState());