Skip to content

Commit 0714b07

Browse files
committed
change assert to avoid flaky in test
Signed-off-by: zane-neo <zaniu@amazon.com>
1 parent 70eb2b1 commit 0714b07

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

plugin/src/test/java/org/opensearch/ml/tools/CatIndexToolIT.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.nio.file.Files;
1010
import java.nio.file.Path;
1111
import java.util.ArrayList;
12+
import java.util.Arrays;
1213
import java.util.List;
1314
import java.util.Objects;
1415

@@ -58,9 +59,8 @@ public void testCatIndexWithFewIndices() throws IOException {
5859
String responseStr = TestHelper.httpEntityToString(response.getEntity());
5960
String toolOutput = extractResult(responseStr);
6061
String[] actualLines = toolOutput.split("\\n");
61-
// plus 2 as there are one line of header and one line of system agent index, but sometimes the ml-config index will be created
62-
// then there will be one more line.
63-
assert actualLines.length == indices.size() + 2 || actualLines.length == indices.size() + 3;
62+
long testIndexCount = Arrays.stream(actualLines).filter(x -> x.contains("test")).count();
63+
assert testIndexCount == indices.size();
6464
for (String index : indices) {
6565
assert Objects.requireNonNull(toolOutput).contains(index);
6666
}
@@ -72,7 +72,8 @@ public void testCatIndexWithMoreThan100Indices() throws IOException {
7272
String responseStr = TestHelper.httpEntityToString(response.getEntity());
7373
String toolOutput = extractResult(responseStr);
7474
String[] actualLines = toolOutput.split("\\n");
75-
assert actualLines.length == indices.size() + 2 || actualLines.length == indices.size() + 3;
75+
long testIndexCount = Arrays.stream(actualLines).filter(x -> x.contains("test")).count();
76+
assert testIndexCount == indices.size();
7677
for (String index : indices) {
7778
assert Objects.requireNonNull(toolOutput).contains(index);
7879
}

0 commit comments

Comments
 (0)