Skip to content

Commit 5d6462a

Browse files
heyamstrask
andauthored
Retry webflux tests 3 times when it's failing (#1712)
* Retry webflux 3 times when it's failing * print stack trace when the final retry fails * Reword Co-authored-by: Trask Stalnaker <[email protected]> Co-authored-by: Trask Stalnaker <[email protected]>
1 parent 747c57d commit 5d6462a

File tree

2 files changed

+45
-0
lines changed
  • test/smoke
    • framework/testCore/src/main/java/com/microsoft/applicationinsights/smoketest
    • testApps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest

2 files changed

+45
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.microsoft.applicationinsights.smoketest;
2+
3+
import org.junit.rules.TestRule;
4+
import org.junit.runner.Description;
5+
import org.junit.runners.model.Statement;
6+
7+
public class Retry implements TestRule {
8+
9+
private final int retryCount;
10+
11+
public Retry(int retryCount) {
12+
this.retryCount = retryCount;
13+
}
14+
15+
@Override
16+
public Statement apply(Statement base, Description description) {
17+
return statement(base, description);
18+
}
19+
20+
private Statement statement(Statement base, Description description) {
21+
return new Statement() {
22+
@Override
23+
public void evaluate() throws Throwable {
24+
Throwable caughtThrowable = null;
25+
for (int i = 0; i < retryCount; i++) {
26+
try {
27+
base.evaluate(); // this will invoke test method, when the test fails, it will throw an AssertionError.
28+
return;
29+
} catch (Throwable t) {
30+
caughtThrowable = t;
31+
System.err.println(description.getDisplayName() + ": run " + (i+1) + " failed");
32+
}
33+
}
34+
System.err.println(description.getDisplayName() + ": giving up after " + retryCount + " failures");
35+
caughtThrowable.printStackTrace();
36+
throw caughtThrowable;
37+
}
38+
};
39+
}
40+
}

test/smoke/testApps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.microsoft.applicationinsights.internal.schemav2.Data;
44
import com.microsoft.applicationinsights.internal.schemav2.Envelope;
55
import com.microsoft.applicationinsights.internal.schemav2.RequestData;
6+
import org.junit.Rule;
67
import org.junit.Test;
78

89
import java.util.List;
@@ -12,6 +13,10 @@
1213
@UseAgent
1314
public class WebFluxTest extends AiSmokeTest {
1415

16+
// TODO revisit and try to get to the bottom of this sporadic failure
17+
@Rule
18+
public Retry retry = new Retry(5);
19+
1520
@Test
1621
@TargetUri("/test")
1722
public void doMostBasicTest() throws Exception {

0 commit comments

Comments
 (0)