Skip to content

Commit 4454de7

Browse files
authored
Fix ILMHistoryItemTests.testTruncateLongError (#125814) (#125818)
It should work independent of how many characters are truncated now. Resolves #125216 (cherry picked from commit de4994d) # Conflicts: # muted-tests.yml
1 parent b768d4e commit 4454de7

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,6 @@ tests:
468468
- class: org.elasticsearch.xpack.inference.external.request.azureopenai.embeddings.AzureOpenAiEmbeddingsRequestTests
469469
method: testCreateRequest_WithEntraIdDefined
470470
issue: https://github.com/elastic/elasticsearch/issues/125061
471-
- class: org.elasticsearch.xpack.ilm.history.ILMHistoryItemTests
472-
method: testTruncateLongError
473-
issue: https://github.com/elastic/elasticsearch/issues/125216
474471
- class: org.elasticsearch.qa.verify_version_constants.VerifyVersionConstantsIT
475472
method: testLuceneVersionConstant
476473
issue: https://github.com/elastic/elasticsearch/issues/125638

x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryItemTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import java.util.Map;
2323

2424
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
25+
import static org.hamcrest.Matchers.containsString;
2526
import static org.hamcrest.Matchers.equalTo;
27+
import static org.hamcrest.Matchers.matchesPattern;
2628
import static org.hamcrest.Matchers.startsWith;
2729

2830
public class ILMHistoryItemTests extends ESTestCase {
@@ -135,15 +137,15 @@ public void testTruncateLongError() throws IOException {
135137
try (XContentParser p = XContentFactory.xContent(XContentType.JSON).createParser(XContentParserConfiguration.EMPTY, json)) {
136138
Map<String, Object> item = p.map();
137139
assertThat(
138-
item.get("error_details"),
139-
equalTo(
140+
(String) item.get("error_details"),
141+
containsString(
140142
"{\"type\":\"illegal_argument_exception\",\"reason\":\""
141143
// We subtract a number of characters here due to the truncation being based
142144
// on the length of the whole string, not just the "reason" part.
143145
+ longError.substring(0, LifecycleExecutionState.MAXIMUM_STEP_INFO_STRING_LENGTH - 47)
144-
+ "... (5126 chars truncated)\"}"
145146
)
146147
);
148+
assertThat((String) item.get("error_details"), matchesPattern(".*\\.\\.\\. \\(\\d+ chars truncated\\).*"));
147149
}
148150
}
149151
}

0 commit comments

Comments
 (0)