Skip to content

Commit c5f60e8

Browse files
committed
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
1 parent 6cc23b7 commit c5f60e8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

server/src/internalClusterTest/java/org/elasticsearch/gateway/ReplicaShardAllocatorIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,10 @@ public void testPreferCopyWithHighestMatchingOperations() throws Exception {
263263
String nodeWithHigherMatching = randomFrom(internalCluster().nodesInclude(indexName));
264264
Settings nodeWithHigherMatchingSettings = internalCluster().dataPathSettings(nodeWithHigherMatching);
265265
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeWithHigherMatching));
266-
indexRandom(randomBoolean(), false, randomBoolean(), IntStream.range(0, between(0, 100))
266+
if (usually()) {
267+
indexRandom(randomBoolean(), false, randomBoolean(), IntStream.range(0, between(1, 100))
267268
.mapToObj(n -> client().prepareIndex(indexName, "_doc").setSource("f", "v")).collect(Collectors.toList()));
269+
}
268270

269271
assertAcked(client().admin().cluster().prepareUpdateSettings()
270272
.setPersistentSettings(Settings.builder().put("cluster.routing.allocation.enable", "primaries").build()));

test/framework/src/main/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,15 @@ public static void assertFailures(SearchRequestBuilder searchRequestBuilder, Res
330330
}
331331

332332
public static void assertNoFailures(BroadcastResponse response) {
333-
assertThat("Unexpected ShardFailures: " + Arrays.toString(response.getShardFailures()), response.getFailedShards(), equalTo(0));
333+
if (response.getFailedShards() != 0) {
334+
final AssertionError assertionError = new AssertionError("[" + response.getFailedShards() + "] shard failures");
335+
336+
for (DefaultShardOperationFailedException shardFailure : response.getShardFailures()) {
337+
assertionError.addSuppressed(new ElasticsearchException(shardFailure.toString(), shardFailure.getCause()));
338+
}
339+
340+
throw assertionError;
341+
}
334342
}
335343

336344
public static void assertAllSuccessful(BroadcastResponse response) {

0 commit comments

Comments
 (0)