Skip to content

Commit 3cc84d0

Browse files
committed
Add details to error message in IndexActionIT
There's a flaky test here that I can't reproduce locally. These details should help with debugging the next time a failure is seen. Signed-off-by: Andrew Ross <andrross@amazon.com>
1 parent da1de97 commit 3cc84d0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.opensearch.index.VersionType;
4545
import org.opensearch.index.mapper.MapperParsingException;
4646
import org.opensearch.indices.InvalidIndexNameException;
47+
import org.opensearch.search.SearchHit;
4748
import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;
4849
import org.opensearch.test.hamcrest.OpenSearchAssertions;
4950

@@ -97,12 +98,22 @@ public void testAutoGenerateIdNoDuplicates() throws Exception {
9798
logger.debug("running search");
9899
SearchResponse response = client().prepareSearch(indexName).get();
99100
if (response.getHits().getTotalHits().value() != numOfDocs) {
101+
// Fetch all docs to identify the unexpected documents
102+
SearchResponse allDocs = client().prepareSearch(indexName)
103+
.setSize((int) response.getHits().getTotalHits().value())
104+
.get();
105+
StringBuilder docDetails = new StringBuilder();
106+
for (SearchHit hit : allDocs.getHits().getHits()) {
107+
docDetails.append("\n id=").append(hit.getId()).append(" source=").append(hit.getSourceAsString());
108+
}
100109
final String message = "Count is "
101110
+ response.getHits().getTotalHits().value()
102111
+ " but "
103112
+ numOfDocs
104113
+ " was expected. "
105-
+ OpenSearchAssertions.formatShardStatus(response);
114+
+ OpenSearchAssertions.formatShardStatus(response)
115+
+ "\nAll documents:"
116+
+ docDetails;
106117
logger.error("{}. search response: \n{}", message, response);
107118
fail(message);
108119
}

0 commit comments

Comments
 (0)