Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flakiness of IndexActionIT.testAutoGenerateIdNoDuplicates #17606

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.opensearch.action.DocWriteResponse;
import org.opensearch.action.admin.indices.refresh.RefreshRequest;
import org.opensearch.action.bulk.BulkResponse;
import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.index.IndexResponse;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.cluster.metadata.MetadataCreateIndexService;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.index.VersionType;
import org.opensearch.index.mapper.MapperParsingException;
import org.opensearch.indices.InvalidIndexNameException;
Expand Down Expand Up @@ -78,23 +80,26 @@ public static Collection<Object[]> parameters() {
*/

public void testAutoGenerateIdNoDuplicates() throws Exception {
final var testIndex = "test";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it important to this test that the same index name is used for each iteration?

int numberOfIterations = scaledRandomIntBetween(10, 50);
for (int i = 0; i < numberOfIterations; i++) {
Exception firstError = null;
createIndex("test");
createIndex(testIndex);
var refRsp = client().admin().indices().refresh(new RefreshRequest(testIndex)).actionGet();
Copy link
Collaborator

@gaobinlong gaobinlong Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refresh the index after the index creation doesn't help, I think, there're no documents in the index, refresh takes no effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can imagine if the async deletion isn’t fully completed, remnants of previous runs may still be visible. This can result in search queries returning a higher total hit count.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by async deletion? createIndex() ensures the old index is deleted and new index is created.

assertSame(RestStatus.OK, refRsp.getStatus());
int numOfDocs = randomIntBetween(10, 100);
logger.info("indexing [{}] docs", numOfDocs);
List<IndexRequestBuilder> builders = new ArrayList<>(numOfDocs);
for (int j = 0; j < numOfDocs; j++) {
builders.add(client().prepareIndex("test").setSource("field", "value_" + j));
builders.add(client().prepareIndex(testIndex).setSource("field", "value_" + j));
}
indexRandom(true, builders);
logger.info("verifying indexed content");
int numOfChecks = randomIntBetween(8, 12);
for (int j = 0; j < numOfChecks; j++) {
try {
logger.debug("running search with all types");
SearchResponse response = client().prepareSearch("test").get();
SearchResponse response = client().prepareSearch(testIndex).get();
if (response.getHits().getTotalHits().value() != numOfDocs) {
final String message = "Count is "
+ response.getHits().getTotalHits().value()
Expand All @@ -113,7 +118,7 @@ public void testAutoGenerateIdNoDuplicates() throws Exception {
}
try {
logger.debug("running search with a specific type");
SearchResponse response = client().prepareSearch("test").get();
SearchResponse response = client().prepareSearch(testIndex).get();
if (response.getHits().getTotalHits().value() != numOfDocs) {
final String message = "Count is "
+ response.getHits().getTotalHits().value()
Expand All @@ -134,7 +139,7 @@ public void testAutoGenerateIdNoDuplicates() throws Exception {
if (firstError != null) {
fail(firstError.getMessage());
}
internalCluster().wipeIndices("test");
internalCluster().wipeIndices(testIndex);
}
}

Expand Down
Loading