Allow warnings about 'global' template in upgrade tests (#59242)

These tests sometimes install a template so they can be compatible with older versions, but they run
amok of the occasionally installed "global" template which changes the default number of shards.

This commit adds `allowedWarnings` and allows these warnings to be present, but doesn't fail if they
are not (since the global template is only randomly installed).

Resolves #58807
Resolves #58258
This commit is contained in:
Lee Hinman 2020-07-08 13:40:55 -06:00 committed by GitHub
parent e50a0330ec
commit bb1c53a0f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 0 deletions

View File

@ -96,6 +96,8 @@ public class IndexingIT extends AbstractRollingTestCase {
Request createTestIndex = new Request("PUT", "/test_index");
createTestIndex.setJsonEntity("{\"settings\": {\"index.number_of_replicas\": 0}}");
client().performRequest(createTestIndex);
allowedWarnings("index [test_index] matches multiple legacy templates [global, prevent-bwc-deprecation-template], " +
"composable templates will only match a single template");
String recoverQuickly = "{\"settings\": {\"index.unassigned.node_left.delayed_timeout\": \"100ms\"}}";
Request createIndexWithReplicas = new Request("PUT", "/index_with_replicas");

View File

@ -75,6 +75,7 @@ import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.util.MockBigArrays;
import org.elasticsearch.common.util.MockPageCacheRecycler;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
@ -430,6 +431,33 @@ public abstract class ESTestCase extends LuceneTestCase {
assertWarnings(true, expectedWarnings);
}
/**
* Allow the given warnings, but don't require their presence.
*/
protected final void allowedWarnings(String... allowedWarnings) {
if (enableWarningsCheck() == false) {
throw new IllegalStateException("unable to check warning headers if the test is not set to do so");
}
try {
final List<String> actualWarnings = threadContext.getResponseHeaders().get("Warning");
if (actualWarnings == null) {
return;
}
final Set<String> actualWarningValues =
actualWarnings.stream()
.map(s -> DeprecationLogger.extractWarningValueFromWarningHeader(s, true))
.map(DeprecationLogger::escapeAndEncode)
.collect(Collectors.toSet());
Set<String> expectedWarnings = new HashSet<>(Arrays.asList(allowedWarnings));
final Set<String> warningsNotExpected = Sets.difference(actualWarningValues, expectedWarnings);
assertThat("Found " + warningsNotExpected.size() + " unexpected warnings\nExpected: "
+ expectedWarnings + "\nActual: " + actualWarningValues,
warningsNotExpected.size(), equalTo(0));
} finally {
resetDeprecationLogger();
}
}
protected final void assertWarnings(boolean stripXContentPosition, String... expectedWarnings) {
if (enableWarningsCheck() == false) {
throw new IllegalStateException("unable to check warning headers if the test is not set to do so");

View File

@ -75,6 +75,8 @@ public class IndexingIT extends AbstractUpgradeTestCase {
Request createTestIndex = new Request("PUT", "/test_index");
createTestIndex.setJsonEntity("{\"settings\": {\"index.number_of_replicas\": 0}}");
client().performRequest(createTestIndex);
allowedWarnings("index [test_index] matches multiple legacy templates [global, xpack-prevent-bwc-deprecation-template], " +
"composable templates will only match a single template");
String recoverQuickly = "{\"settings\": {\"index.unassigned.node_left.delayed_timeout\": \"100ms\"}}";
Request createIndexWithReplicas = new Request("PUT", "/index_with_replicas");

View File

@ -89,6 +89,8 @@ public class TokenBackwardsCompatibilityIT extends AbstractUpgradeTestCase {
assertNotNull(refreshToken);
storeTokens(client(), 1, accessToken, refreshToken);
allowedWarnings("index [token_backwards_compatibility_it] matches multiple legacy templates " +
"[gen-tokens-old-cluster-template, global], composable templates will only match a single template");
responseMap = createTokens(client(), "test_user", "x-pack-test-password");
accessToken = (String) responseMap.get("access_token");
@ -175,6 +177,8 @@ public class TokenBackwardsCompatibilityIT extends AbstractUpgradeTestCase {
assertNotNull(refreshToken);
storeTokens(client(), 5, accessToken, refreshToken);
allowedWarnings("index [token_backwards_compatibility_it] matches multiple legacy templates " +
"[global, invalid-tokens-old-cluster-template], composable templates will only match a single template");
// invalidate access token
invalidateAccessToken(client(), accessToken);