Skip to content

Commit de4994d

Browse files
authored
Fix ILMHistoryItemTests.testTruncateLongError (#125814)
It should work independent of how many characters are truncated now. Resolves #125216
1 parent a0dce5c commit de4994d

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

muted-tests.yml

-3
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,6 @@ tests:
338338
- class: org.elasticsearch.index.engine.ThreadPoolMergeSchedulerTests
339339
method: testSchedulerCloseWaitsForRunningMerge
340340
issue: https://github.com/elastic/elasticsearch/issues/125236
341-
- class: org.elasticsearch.xpack.ilm.history.ILMHistoryItemTests
342-
method: testTruncateLongError
343-
issue: https://github.com/elastic/elasticsearch/issues/125216
344341
- class: org.elasticsearch.index.shard.StoreRecoveryTests
345342
method: testAddIndices
346343
issue: https://github.com/elastic/elasticsearch/issues/124104

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

+5-3
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)