Skip to content

Commit c8066a0

Browse files
iigoninbennygoerzigKarstenSchnitterKai Sternad
committed
Fix flakiness of IndexActionIT.testAutoGenerateIdNoDuplicates
Signed-off-by: Igonin <[email protected]> Co-authored-by: Benny Goerzig <[email protected]> Co-authored-by: Karsten Schnitter <[email protected]> Co-authored-by: Kai Sternad <[email protected]>
1 parent 1275017 commit c8066a0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
3636

3737
import org.opensearch.action.DocWriteResponse;
38+
import org.opensearch.action.admin.indices.refresh.RefreshRequest;
3839
import org.opensearch.action.bulk.BulkResponse;
3940
import org.opensearch.action.index.IndexRequestBuilder;
4041
import org.opensearch.action.index.IndexResponse;
4142
import org.opensearch.action.search.SearchResponse;
4243
import org.opensearch.cluster.metadata.MetadataCreateIndexService;
4344
import org.opensearch.common.settings.Settings;
45+
import org.opensearch.core.rest.RestStatus;
4446
import org.opensearch.index.VersionType;
4547
import org.opensearch.index.mapper.MapperParsingException;
4648
import org.opensearch.indices.InvalidIndexNameException;
@@ -78,23 +80,26 @@ public static Collection<Object[]> parameters() {
7880
*/
7981

8082
public void testAutoGenerateIdNoDuplicates() throws Exception {
83+
final var testIndex = "test";
8184
int numberOfIterations = scaledRandomIntBetween(10, 50);
8285
for (int i = 0; i < numberOfIterations; i++) {
8386
Exception firstError = null;
84-
createIndex("test");
87+
createIndex(testIndex);
88+
var refRsp = client().admin().indices().refresh(new RefreshRequest(testIndex)).actionGet();
89+
assertSame(RestStatus.OK, refRsp.getStatus());
8590
int numOfDocs = randomIntBetween(10, 100);
8691
logger.info("indexing [{}] docs", numOfDocs);
8792
List<IndexRequestBuilder> builders = new ArrayList<>(numOfDocs);
8893
for (int j = 0; j < numOfDocs; j++) {
89-
builders.add(client().prepareIndex("test").setSource("field", "value_" + j));
94+
builders.add(client().prepareIndex(testIndex).setSource("field", "value_" + j));
9095
}
9196
indexRandom(true, builders);
9297
logger.info("verifying indexed content");
9398
int numOfChecks = randomIntBetween(8, 12);
9499
for (int j = 0; j < numOfChecks; j++) {
95100
try {
96101
logger.debug("running search with all types");
97-
SearchResponse response = client().prepareSearch("test").get();
102+
SearchResponse response = client().prepareSearch(testIndex).get();
98103
if (response.getHits().getTotalHits().value() != numOfDocs) {
99104
final String message = "Count is "
100105
+ response.getHits().getTotalHits().value()
@@ -113,7 +118,7 @@ public void testAutoGenerateIdNoDuplicates() throws Exception {
113118
}
114119
try {
115120
logger.debug("running search with a specific type");
116-
SearchResponse response = client().prepareSearch("test").get();
121+
SearchResponse response = client().prepareSearch(testIndex).get();
117122
if (response.getHits().getTotalHits().value() != numOfDocs) {
118123
final String message = "Count is "
119124
+ response.getHits().getTotalHits().value()
@@ -134,7 +139,7 @@ public void testAutoGenerateIdNoDuplicates() throws Exception {
134139
if (firstError != null) {
135140
fail(firstError.getMessage());
136141
}
137-
internalCluster().wipeIndices("test");
142+
internalCluster().wipeIndices(testIndex);
138143
}
139144
}
140145

0 commit comments

Comments
 (0)