Skip to content

Commit 6dd0ca8

Browse files
authored
Remove redundant step from IndexActionIT#testAutoGenerateIdNoDuplicates (opensearch-project#18630)
testAutoGenerateIdNoDuplicates was modified back in 2014 to search all docs in the index and to search all docs of a given type in the index. When types were removed in OpenSearch 2.0, that second check had the type removed, making it identical to the first check. This change essentially goes back to the pre-2014 version, when the test was just searching all docs in the index once. Also, I modified the test to change index names on every iteration in the hope that it becomes a bit less flaky. Generating a different index on every iteration does not appear to violate the spirit of the test. Signed-off-by: Michael Froh <[email protected]>
1 parent b1d6f55 commit 6dd0ca8

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

server/src/internalClusterTest/java/org/opensearch/indexing/IndexActionIT.java

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,22 @@ public static Collection<Object[]> parameters() {
8080
public void testAutoGenerateIdNoDuplicates() throws Exception {
8181
int numberOfIterations = scaledRandomIntBetween(10, 50);
8282
for (int i = 0; i < numberOfIterations; i++) {
83+
String indexName = "test-" + i;
8384
Exception firstError = null;
84-
createIndex("test");
85+
createIndex(indexName);
8586
int numOfDocs = randomIntBetween(10, 100);
8687
logger.info("indexing [{}] docs", numOfDocs);
8788
List<IndexRequestBuilder> builders = new ArrayList<>(numOfDocs);
8889
for (int j = 0; j < numOfDocs; j++) {
89-
builders.add(client().prepareIndex("test").setSource("field", "value_" + j));
90+
builders.add(client().prepareIndex(indexName).setSource("field", "value_" + j));
9091
}
9192
indexRandom(true, builders);
9293
logger.info("verifying indexed content");
9394
int numOfChecks = randomIntBetween(8, 12);
9495
for (int j = 0; j < numOfChecks; j++) {
9596
try {
96-
logger.debug("running search with all types");
97-
SearchResponse response = client().prepareSearch("test").get();
97+
logger.debug("running search");
98+
SearchResponse response = client().prepareSearch(indexName).get();
9899
if (response.getHits().getTotalHits().value() != numOfDocs) {
99100
final String message = "Count is "
100101
+ response.getHits().getTotalHits().value()
@@ -106,26 +107,7 @@ public void testAutoGenerateIdNoDuplicates() throws Exception {
106107
fail(message);
107108
}
108109
} catch (Exception e) {
109-
logger.error("search for all docs types failed", e);
110-
if (firstError == null) {
111-
firstError = e;
112-
}
113-
}
114-
try {
115-
logger.debug("running search with a specific type");
116-
SearchResponse response = client().prepareSearch("test").get();
117-
if (response.getHits().getTotalHits().value() != numOfDocs) {
118-
final String message = "Count is "
119-
+ response.getHits().getTotalHits().value()
120-
+ " but "
121-
+ numOfDocs
122-
+ " was expected. "
123-
+ OpenSearchAssertions.formatShardStatus(response);
124-
logger.error("{}. search response: \n{}", message, response);
125-
fail(message);
126-
}
127-
} catch (Exception e) {
128-
logger.error("search for all docs of a specific type failed", e);
110+
logger.error("search for all docs failed", e);
129111
if (firstError == null) {
130112
firstError = e;
131113
}
@@ -134,7 +116,7 @@ public void testAutoGenerateIdNoDuplicates() throws Exception {
134116
if (firstError != null) {
135117
fail(firstError.getMessage());
136118
}
137-
internalCluster().wipeIndices("test");
119+
internalCluster().wipeIndices(indexName);
138120
}
139121
}
140122

0 commit comments

Comments
 (0)