소스 검색

Unmute and fix TransportClusterHealthActionTests tests (#78996)

Adjust TransportClusterHealthActionTests to not create an unassigned primary.
shard. The cluster health api now relies RoutingNodes and that has assertions
that disallow a replica shard that is initializing / relocation who's primary
shard is unassigned.

Closes #78978
Martijn van Groningen 4 년 전
부모
커밋
6d2a899a63
1개의 변경된 파일12개의 추가작업 그리고 5개의 파일을 삭제
  1. 12 5
      server/src/test/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthActionTests.java

+ 12 - 5
server/src/test/java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthActionTests.java

@@ -32,7 +32,6 @@ import static org.hamcrest.core.IsEqual.equalTo;
 
 public class TransportClusterHealthActionTests extends ESTestCase {
 
-    @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/78978")
     public void testWaitForInitializingShards() throws Exception {
         final String[] indices = {"test"};
         final ClusterHealthRequest request = new ClusterHealthRequest();
@@ -52,7 +51,6 @@ public class TransportClusterHealthActionTests extends ESTestCase {
         assertThat(TransportClusterHealthAction.prepareResponse(request, response, clusterState, null), equalTo(0));
     }
 
-    @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/78978")
     public void testWaitForAllShards() {
         final String[] indices = {"test"};
         final ClusterHealthRequest request = new ClusterHealthRequest();
@@ -81,15 +79,23 @@ public class TransportClusterHealthActionTests extends ESTestCase {
         IntStream.range(0, initializingShards).forEach(i -> shardRoutingStates.add(ShardRoutingState.INITIALIZING));
         Randomness.shuffle(shardRoutingStates);
 
+        // primary can not be unassigned, otherwise replicas can't in initializing or relocating state.
+        // (assertion in RoutingNodes disallows this)
+        if (shardRoutingStates.get(0) == ShardRoutingState.UNASSIGNED) {
+            // Don't randomly pick ShardRoutingState.UNASSIGNED, since that already has randomly been inserted based on initializingShards
+            shardRoutingStates.set(0, randomFrom(ShardRoutingState.STARTED, ShardRoutingState.RELOCATING));
+        }
+
         final ShardId shardId = new ShardId(new Index("index", "uuid"), 0);
         final IndexRoutingTable.Builder routingTable = new IndexRoutingTable.Builder(indexMetadata.getIndex());
 
         // Primary
         {
             ShardRoutingState state = shardRoutingStates.remove(0);
-            String node = state == ShardRoutingState.UNASSIGNED ? null : "node";
+            String node = "node";
+            String relocatingNode = state == ShardRoutingState.RELOCATING ? "relocating" : null;
             routingTable.addShard(
-                TestShardRouting.newShardRouting(shardId, node, "relocating", true, state)
+                TestShardRouting.newShardRouting(shardId, node, relocatingNode, true, state)
             );
         }
 
@@ -97,7 +103,8 @@ public class TransportClusterHealthActionTests extends ESTestCase {
         for (int i = 0; i < shardRoutingStates.size(); i++) {
             ShardRoutingState state = shardRoutingStates.get(i);
             String node = state == ShardRoutingState.UNASSIGNED ? null : "node" + i;
-            routingTable.addShard(TestShardRouting.newShardRouting(shardId, node, "relocating"+i, randomBoolean(), state));
+            String relocatingNode = state == ShardRoutingState.RELOCATING ? "relocating" + i : null;
+            routingTable.addShard(TestShardRouting.newShardRouting(shardId, node, relocatingNode, false, state));
         }
 
         return ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))