Skip to content

Commit b5226ef

Browse files
Reduce CartesianCentroidIT flakiness (#91553)
* Reduced flakiness for CartesianCentroidIT The property tests were still considering a tolerance specific to geo data * Reduced flakiness for CartesianCentroidIT When values are very small (close to zero), the tolerance calculation gives smaller values than even the float rounding.
1 parent 1f72f2e commit b5226ef

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

test/framework/src/main/java/org/elasticsearch/search/aggregations/metrics/CentroidAggregationTestBase.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,15 @@ public void testSingleValueFieldGetProperty() {
103103
assertThat(global.getAggregations().asMap().size(), equalTo(1));
104104

105105
CentroidAggregation geoCentroid = global.getAggregations().get(aggName());
106+
InternalAggregation agg = (InternalAggregation) global;
106107
assertThat(geoCentroid, notNullValue());
107108
assertThat(geoCentroid.getName(), equalTo(aggName()));
108-
assertThat((CentroidAggregation) ((InternalAggregation) global).getProperty(aggName()), sameInstance(geoCentroid));
109+
assertThat((CentroidAggregation) agg.getProperty(aggName()), sameInstance(geoCentroid));
109110
assertSameCentroid(geoCentroid.centroid(), singleCentroid);
110-
assertThat(
111-
((SpatialPoint) ((InternalAggregation) global).getProperty(aggName() + ".value")).getY(),
112-
closeTo(singleCentroid.getY(), GEOHASH_TOLERANCE)
113-
);
114-
assertThat(
115-
((SpatialPoint) ((InternalAggregation) global).getProperty(aggName() + ".value")).getX(),
116-
closeTo(singleCentroid.getX(), GEOHASH_TOLERANCE)
117-
);
118-
assertThat(
119-
(double) ((InternalAggregation) global).getProperty(aggName() + "." + coordinateName("y")),
120-
closeTo(singleCentroid.getY(), GEOHASH_TOLERANCE)
121-
);
122-
assertThat(
123-
(double) ((InternalAggregation) global).getProperty(aggName() + "." + coordinateName("x")),
124-
closeTo(singleCentroid.getX(), GEOHASH_TOLERANCE)
125-
);
111+
assertSimilarValue(((SpatialPoint) agg.getProperty(aggName() + ".value")).getY(), singleCentroid.getY());
112+
assertSimilarValue(((SpatialPoint) agg.getProperty(aggName() + ".value")).getX(), singleCentroid.getX());
113+
assertSimilarValue((double) agg.getProperty(aggName() + "." + coordinateName("y")), singleCentroid.getY());
114+
assertSimilarValue((double) agg.getProperty(aggName() + "." + coordinateName("x")), singleCentroid.getX());
126115
assertEquals(numDocs, (long) ((InternalAggregation) global).getProperty(aggName() + ".count"));
127116
}
128117

@@ -155,6 +144,12 @@ protected double normalize(double value) {
155144
return value;
156145
}
157146

147+
protected void assertSimilarValue(double a, double b) {
148+
a = normalize(a);
149+
b = normalize(b);
150+
assertThat(a, closeTo(b, tolerance(a, b)));
151+
}
152+
158153
protected void assertSameCentroid(SpatialPoint centroid, SpatialPoint expectedCentroid) {
159154
String[] names = centroid.getClass() == GeoPoint.class ? new String[] { "longitude", "latitude" } : new String[] { "x", "y" };
160155
double x = normalize(centroid.getX());

x-pack/plugin/spatial/src/internalClusterTest/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics/CartesianCentroidIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected CartesianPoint reset(SpatialPoint point, double x, double y) {
7171

7272
@Override
7373
protected double tolerance(double a, double b) {
74-
return Math.max(Math.abs(a), Math.abs(b)) / 1e5;
74+
return Math.max(GEOHASH_TOLERANCE, Math.max(Math.abs(a), Math.abs(b)) / 1e5);
7575
}
7676

7777
@Override

0 commit comments

Comments
 (0)