Skip to content

Commit 4ca5e3f

Browse files
[ML][TEST] Fix bucket count assertion in ModelPlotsIT (#30717)
As the first record is random, there's a chance it will be aligned on a bucket start. Thus we need to check the bucket count is in [23, 24]. Closes #30715
1 parent da6bf42 commit 4ca5e3f

File tree

1 file changed

+12
-2
lines changed
  • x-pack/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration

1 file changed

+12
-2
lines changed

x-pack/qa/ml-native-tests/src/test/java/org/elasticsearch/xpack/ml/integration/ModelPlotsIT.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030

3131
import static org.hamcrest.Matchers.containsInAnyOrder;
3232
import static org.hamcrest.Matchers.equalTo;
33+
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3334
import static org.hamcrest.Matchers.is;
35+
import static org.hamcrest.Matchers.lessThanOrEqualTo;
3436

3537
public class ModelPlotsIT extends MlNativeAutodetectIntegTestCase {
3638

@@ -83,7 +85,11 @@ public void testPartitionFieldWithoutTerms() throws Exception {
8385
startDatafeed(datafeedId, 0, System.currentTimeMillis());
8486
waitUntilJobIsClosed(job.getId());
8587

86-
assertThat(getBuckets(job.getId()).size(), equalTo(23));
88+
// As the initial time is random, there's a chance the first record is
89+
// aligned on a bucket start. Thus we check the buckets are in [23, 24]
90+
assertThat(getBuckets(job.getId()).size(), greaterThanOrEqualTo(23));
91+
assertThat(getBuckets(job.getId()).size(), lessThanOrEqualTo(24));
92+
8793
Set<String> modelPlotTerms = modelPlotTerms(job.getId(), "partition_field_value");
8894
assertThat(modelPlotTerms, containsInAnyOrder("user_1", "user_2", "user_3"));
8995
}
@@ -101,7 +107,11 @@ public void testPartitionFieldWithTerms() throws Exception {
101107
startDatafeed(datafeedId, 0, System.currentTimeMillis());
102108
waitUntilJobIsClosed(job.getId());
103109

104-
assertThat(getBuckets(job.getId()).size(), equalTo(23));
110+
// As the initial time is random, there's a chance the first record is
111+
// aligned on a bucket start. Thus we check the buckets are in [23, 24]
112+
assertThat(getBuckets(job.getId()).size(), greaterThanOrEqualTo(23));
113+
assertThat(getBuckets(job.getId()).size(), lessThanOrEqualTo(24));
114+
105115
Set<String> modelPlotTerms = modelPlotTerms(job.getId(), "partition_field_value");
106116
assertThat(modelPlotTerms, containsInAnyOrder("user_2", "user_3"));
107117
}

0 commit comments

Comments
 (0)