Skip to content

Commit

Permalink
Fix testPreferCopyWithHighestMatchingOperations (#75170)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DaveCTurner committed Jul 13, 2021
1 parent 948f09f commit e89e16b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ public void testPreferCopyWithHighestMatchingOperations() throws Exception {
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))
if (usually()) {
indexRandom(randomBoolean(), false, randomBoolean(), IntStream.range(0, between(1, 100))
.mapToObj(n -> client().prepareIndex(indexName, "_doc").setSource("f", "v")).collect(Collectors.toList()));
}

assertAcked(client().admin().cluster().prepareUpdateSettings()
.setPersistentSettings(Settings.builder().put("cluster.routing.allocation.enable", "primaries").build()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,15 @@ public static void assertFailures(SearchRequestBuilder searchRequestBuilder, Res
}

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) {
Expand Down

0 comments on commit e89e16b

Please sign in to comment.