Skip to content

Commit 2a1adad

Browse files
authored
Address precision issue in IndexDiskUsageAnalyzerTests#testCompletionFields (#125849) (#125951) (#125963)
We have some tolerance wound how many bytes we report for these completion fields. But the values depend on the distribution of the random values that determine how many docs get an option field. This commit makes the test more precise by computing the real ratio between docs that have the optional field and the total number of docs, so that we can base assertion on more realistic expectations. Closes #123269
1 parent 05fe506 commit 2a1adad

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

server/src/test/java/org/elasticsearch/action/admin/indices/diskusage/IndexDiskUsageAnalyzerTests.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -339,23 +339,27 @@ public PostingsFormat getPostingsFormatForField(String field) {
339339
});
340340

341341
try (Directory dir = createNewDirectory()) {
342+
float docsWithSuggest1FieldRatio;
342343
try (IndexWriter writer = new IndexWriter(dir, config)) {
343344
int numDocs = randomIntBetween(100, 1000);
345+
int numDocsWithSuggest1Field = 0;
344346
for (int i = 0; i < numDocs; i++) {
345347
final Document doc = new Document();
346348
if (randomDouble() < 0.5) {
349+
numDocsWithSuggest1Field++;
347350
doc.add(new SuggestField("suggest_1", randomAlphaOfLength(10), randomIntBetween(1, 20)));
348351
}
349352
doc.add(new SuggestField("suggest_2", randomAlphaOfLength(10), randomIntBetween(1, 20)));
350353
writer.addDocument(doc);
351354
}
355+
docsWithSuggest1FieldRatio = (float) numDocsWithSuggest1Field / (numDocs + numDocsWithSuggest1Field);
352356
}
353357
final IndexDiskUsageStats stats = IndexDiskUsageAnalyzer.analyze(testShardId(), lastCommit(dir), () -> {});
354358
assertFieldStats(
355359
"suggest_1",
356360
"inverted_index",
357361
stats.getFields().get("suggest_1").getInvertedIndexBytes(),
358-
stats.total().totalBytes() / 3,
362+
(long) (stats.total().totalBytes() * docsWithSuggest1FieldRatio),
359363
0.05,
360364
2048
361365
);
@@ -364,7 +368,7 @@ public PostingsFormat getPostingsFormatForField(String field) {
364368
"suggest_2",
365369
"inverted_index",
366370
stats.getFields().get("suggest_2").getInvertedIndexBytes(),
367-
stats.total().totalBytes() * 2 / 3,
371+
(long) (stats.total().totalBytes() * (1 - docsWithSuggest1FieldRatio)),
368372
0.05,
369373
2048
370374
);

0 commit comments

Comments
 (0)