瀏覽代碼

Fix testPreferCopyWithHighestMatchingOperations (#75170)

In #74081 this test failed with a `NoNodeAvailableException` within the
`indexRandom()` call immediately after stopping a node. This could
happen if the `node-left` event wasn't fully applied before calling
`indexRandom()` with an empty list of docs but with `forceRefresh` set
to true: since there's no docs, the replica wouldn't be marked as stale,
so the final refresh would detect the missing node, failing its
`assertNoFailures` wrapper.

This commit avoids calling `indexRandom()` with no docs in this
location. It also enhances `assertNoFailures` to report the details of
each failure, rather than just the summary.

Closes #74081
David Turner 4 年之前
父節點
當前提交
f8185e5702

+ 4 - 2
server/src/internalClusterTest/java/org/elasticsearch/gateway/ReplicaShardAllocatorIT.java

@@ -252,8 +252,10 @@ public class ReplicaShardAllocatorIT extends ESIntegTestCase {
         String nodeWithHigherMatching = randomFrom(internalCluster().nodesInclude(indexName));
         Settings nodeWithHigherMatchingSettings = internalCluster().dataPathSettings(nodeWithHigherMatching);
         internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeWithHigherMatching));
-        indexRandom(randomBoolean(), false, randomBoolean(), IntStream.range(0, between(0, 100))
-            .mapToObj(n -> client().prepareIndex(indexName).setSource("f", "v")).collect(Collectors.toList()));
+        if (usually()) {
+            indexRandom(randomBoolean(), false, randomBoolean(), IntStream.range(0, between(1, 100))
+                .mapToObj(n -> client().prepareIndex(indexName).setSource("f", "v")).collect(Collectors.toList()));
+        }
 
         assertAcked(client().admin().cluster().prepareUpdateSettings()
             .setPersistentSettings(Settings.builder().put("cluster.routing.allocation.enable", "primaries").build()));

+ 9 - 1
test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java

@@ -327,7 +327,15 @@ public class ElasticsearchAssertions {
     }
 
     public static void assertNoFailures(BroadcastResponse response) {
-        assertThat("Unexpected ShardFailures: " + Arrays.toString(response.getShardFailures()), response.getFailedShards(), equalTo(0));
+        if (response.getFailedShards() != 0) {
+            final AssertionError assertionError = new AssertionError("[" + response.getFailedShards() + "] shard failures");
+
+            for (DefaultShardOperationFailedException shardFailure : response.getShardFailures()) {
+                assertionError.addSuppressed(new ElasticsearchException(shardFailure.toString(), shardFailure.getCause()));
+            }
+
+            throw assertionError;
+        }
     }
 
     public static void assertAllSuccessful(BroadcastResponse response) {