Skip to content

Commit 3c526ac

Browse files
committed
Use TestNG retry to reduce flakiness in probabilistic result validation
1 parent e03eff1 commit 3c526ac

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed

presto-main-base/src/test/java/com/facebook/presto/operator/aggregation/noisyaggregation/TestNoisySumGaussianLongAggregation.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import com.facebook.presto.testing.LocalQueryRunner;
2525
import com.facebook.presto.testing.MaterializedResult;
2626
import com.facebook.presto.testing.MaterializedRow;
27+
import com.facebook.presto.util.RetryAnalyzer;
28+
import com.facebook.presto.util.RetryCount;
2729
import org.testng.annotations.Test;
2830

2931
import java.util.Arrays;
@@ -422,7 +424,8 @@ public void testNoisySumGaussianLongClippingSomeNoiseScale()
422424
expected);
423425
}
424426

425-
@Test
427+
@Test(retryAnalyzer = RetryAnalyzer.class)
428+
@RetryCount(100)
426429
public void testNoisySumGaussianLongClippingSomeNoiseScaleWithinSomeStd()
427430
{
428431
JavaAggregationFunctionImplementation noisySumGaussian = getFunction(BIGINT, DOUBLE, DOUBLE, DOUBLE);

presto-main-base/src/test/java/com/facebook/presto/operator/aggregation/noisyaggregation/TestNoisySumGaussianLongDecimalAggregation.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import com.facebook.presto.testing.LocalQueryRunner;
2626
import com.facebook.presto.testing.MaterializedResult;
2727
import com.facebook.presto.testing.MaterializedRow;
28+
import com.facebook.presto.util.RetryAnalyzer;
29+
import com.facebook.presto.util.RetryCount;
2830
import org.testng.annotations.Test;
2931

3032
import java.util.Arrays;
@@ -281,7 +283,8 @@ public void testNoisySumGaussianLongDecimalClippingSomeNoiseScale()
281283
expected);
282284
}
283285

284-
@Test
286+
@Test(retryAnalyzer = RetryAnalyzer.class)
287+
@RetryCount(100)
285288
public void testNoisySumGaussianLongDecimalClippingSomeNoiseScaleWithinSomeStd()
286289
{
287290
JavaAggregationFunctionImplementation noisySumGaussian = getFunction(LONG_DECIMAL_TYPE, DOUBLE, DOUBLE, DOUBLE);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.util;
15+
16+
import org.testng.IRetryAnalyzer;
17+
import org.testng.ITestResult;
18+
19+
import java.lang.reflect.Method;
20+
21+
import static com.facebook.presto.util.RetryCount.DEFAULT_RETRY_COUNT;
22+
23+
public class RetryAnalyzer
24+
implements IRetryAnalyzer
25+
{
26+
private int retryCount;
27+
private int maxRetryCount;
28+
29+
@Override
30+
public boolean retry(ITestResult result)
31+
{
32+
if (maxRetryCount == 0) {
33+
Method method = result.getMethod().getConstructorOrMethod().getMethod();
34+
RetryCount annotation = method.getAnnotation(RetryCount.class);
35+
maxRetryCount = (annotation != null) ? annotation.value() : DEFAULT_RETRY_COUNT;
36+
}
37+
return retryCount++ < maxRetryCount;
38+
}
39+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.util;
15+
16+
import java.lang.annotation.Retention;
17+
import java.lang.annotation.RetentionPolicy;
18+
19+
@Retention(RetentionPolicy.RUNTIME)
20+
public @interface RetryCount
21+
{
22+
int DEFAULT_RETRY_COUNT = 3;
23+
int value() default DEFAULT_RETRY_COUNT;
24+
}

0 commit comments

Comments
 (0)