Skip to content

Commit 8e0cb53

Browse files
opensearch-trigger-bot[bot]github-actions[bot]LantaoJin
authored
[Backport 2.19-dev] Add flaky retry on CalcitePPLTpchIT (opensearch-project#4089)
* Add flaky retry on CalcitePPLTpchIT (opensearch-project#4060) * Add flaky retry on CalcitePPLTpchIT.testQ7 Signed-off-by: Lantao Jin <ltjin@amazon.com> * Add retry to all tpch queries Signed-off-by: Lantao Jin <ltjin@amazon.com> * address comments Signed-off-by: Lantao Jin <ltjin@amazon.com> --------- Signed-off-by: Lantao Jin <ltjin@amazon.com> (cherry picked from commit be38740) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Fix retry annotation for class Signed-off-by: Lantao Jin <ltjin@amazon.com> * Ignore testQ7 in macOS Signed-off-by: Lantao Jin <ltjin@amazon.com> --------- Signed-off-by: Lantao Jin <ltjin@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Lantao Jin <ltjin@amazon.com>
1 parent c585a7a commit 8e0cb53

4 files changed

Lines changed: 79 additions & 1 deletion

File tree

integ-test/src/test/java/org/opensearch/sql/calcite/tpch/CalcitePPLTpchIT.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
import static org.opensearch.sql.util.MatcherUtils.verifySchemaInOrder;
1515

1616
import java.io.IOException;
17+
import java.util.Locale;
18+
1719
import org.json.JSONObject;
20+
import org.junit.Assume;
1821
import org.junit.Ignore;
1922
import org.junit.Test;
2023
import org.opensearch.sql.ppl.PPLIntegTestCase;
24+
import org.opensearch.sql.util.Retry;
2125

26+
@Retry
2227
public class CalcitePPLTpchIT extends PPLIntegTestCase {
2328

2429
@Override
@@ -142,7 +147,6 @@ public void testQ3() throws IOException {
142147
// TODO: Aggregation push down has a hard-coded limit of 1000 buckets for output, so this query
143148
// will not return the correct results with aggregation push down and it's unstable
144149
@Ignore
145-
@Test
146150
public void testQ4() throws IOException {
147151
String ppl = sanitize(loadFromFile("tpch/queries/q4.ppl"));
148152
JSONObject actual = executeQuery(ppl);
@@ -173,7 +177,10 @@ public void testQ6() throws IOException {
173177
verifyDataRows(actual, rows(77949.9186));
174178
}
175179

180+
@Test
176181
public void testQ7() throws IOException {
182+
String osName = System.getProperty("os.name").toLowerCase(Locale.ROOT);
183+
Assume.assumeFalse("testQ7 on macOS CI could socket timeout", osName.contains("mac"));
177184
String ppl = sanitize(loadFromFile("tpch/queries/q7.ppl"));
178185
JSONObject actual = executeQuery(ppl);
179186
verifySchemaInOrder(
@@ -185,6 +192,7 @@ public void testQ7() throws IOException {
185192
verifyNumOfRows(actual, 0);
186193
}
187194

195+
@Test
188196
public void testQ8() throws IOException {
189197
String ppl = sanitize(loadFromFile("tpch/queries/q8.ppl"));
190198
JSONObject actual = executeQuery(ppl);

integ-test/src/test/java/org/opensearch/sql/ppl/PPLIntegTestCase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.json.JSONException;
2222
import org.json.JSONObject;
2323
import org.junit.Assert;
24+
import org.junit.Rule;
2425
import org.opensearch.client.Request;
2526
import org.opensearch.client.RequestOptions;
2627
import org.opensearch.client.Response;
@@ -29,10 +30,12 @@
2930
import org.opensearch.sql.common.setting.Settings;
3031
import org.opensearch.sql.common.setting.Settings.Key;
3132
import org.opensearch.sql.legacy.SQLIntegTestCase;
33+
import org.opensearch.sql.util.RetryProcessor;
3234

3335
/** OpenSearch Rest integration test base for PPL testing. */
3436
public abstract class PPLIntegTestCase extends SQLIntegTestCase {
3537
private static final Logger LOG = LogManager.getLogger();
38+
@Rule public final RetryProcessor retryProcessor = new RetryProcessor();
3639

3740
@Override
3841
protected void init() throws Exception {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.sql.util;
7+
8+
import java.lang.annotation.ElementType;
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.RetentionPolicy;
11+
import java.lang.annotation.Target;
12+
13+
/**
14+
* Retry annotation to indicate a test should be retried when exception happens. The default retry
15+
* count is 3. You can specify the retry count by passing a value to the annotation. For
16+
* example: @Retry(5)
17+
*/
18+
@Target({ElementType.TYPE, ElementType.METHOD})
19+
@Retention(RetentionPolicy.RUNTIME)
20+
public @interface Retry {
21+
int value() default 3;
22+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.sql.util;
7+
8+
import java.util.Optional;
9+
import org.apache.logging.log4j.LogManager;
10+
import org.apache.logging.log4j.Logger;
11+
import org.junit.rules.TestWatcher;
12+
import org.junit.runner.Description;
13+
import org.junit.runners.model.Statement;
14+
15+
/** Retry processor to retry a test when exception happens. Retry a test by adding @Retry. */
16+
public class RetryProcessor extends TestWatcher {
17+
private static final Logger LOG = LogManager.getLogger();
18+
19+
@Override
20+
public Statement apply(Statement base, Description description) {
21+
Retry retry =
22+
Optional.ofNullable(description.getAnnotation(Retry.class))
23+
.orElseGet(() -> description.getTestClass().getAnnotation(Retry.class));
24+
if (retry == null) {
25+
return base;
26+
}
27+
return new Statement() {
28+
@Override
29+
public void evaluate() throws Throwable {
30+
Throwable lastException = null;
31+
for (int i = 0; i < retry.value(); i++) {
32+
try {
33+
base.evaluate();
34+
return;
35+
} catch (Throwable t) {
36+
lastException = t;
37+
LOG.info("Retrying {} {} times", description.getDisplayName(), (i + 1));
38+
}
39+
}
40+
assert lastException != null;
41+
throw lastException;
42+
}
43+
};
44+
}
45+
}

0 commit comments

Comments
 (0)