-
Notifications
You must be signed in to change notification settings - Fork 2k
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -78,23 +80,26 @@ public static Collection<Object[]> parameters() { | |
*/ | ||
|
||
public void testAutoGenerateIdNoDuplicates() throws Exception { | ||
final var testIndex = "test"; | ||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
@@ -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() | ||
|
@@ -134,7 +139,7 @@ public void testAutoGenerateIdNoDuplicates() throws Exception { | |
if (firstError != null) { | ||
fail(firstError.getMessage()); | ||
} | ||
internalCluster().wipeIndices("test"); | ||
internalCluster().wipeIndices(testIndex); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
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?