File tree Expand file tree Collapse file tree 3 files changed +66
-3
lines changed
downloader/src/test/java/org/enso/downloader/http
testkit/src/main/java/org/enso/testkit Expand file tree Collapse file tree 3 files changed +66
-3
lines changed Original file line number Diff line number Diff line change @@ -1092,9 +1092,11 @@ lazy val testkit = project
1092
1092
.settings(
1093
1093
frgaalJavaCompilerSetting,
1094
1094
libraryDependencies ++= Seq (
1095
- " org.apache.commons" % " commons-lang3" % commonsLangVersion,
1096
- " commons-io" % " commons-io" % commonsIoVersion,
1097
- " org.scalatest" %% " scalatest" % scalatestVersion
1095
+ " org.apache.commons" % " commons-lang3" % commonsLangVersion,
1096
+ " commons-io" % " commons-io" % commonsIoVersion,
1097
+ " org.scalatest" %% " scalatest" % scalatestVersion,
1098
+ " junit" % " junit" % junitVersion,
1099
+ " com.github.sbt" % " junit-interface" % junitIfVersion
1098
1100
)
1099
1101
)
1100
1102
@@ -2552,6 +2554,7 @@ lazy val downloader = (project in file("lib/scala/downloader"))
2552
2554
)
2553
2555
.dependsOn(cli)
2554
2556
.dependsOn(`http-test-helper`)
2557
+ .dependsOn(testkit % Test )
2555
2558
2556
2559
lazy val `edition-updater` = project
2557
2560
.in(file(" lib/scala/edition-updater" ))
Original file line number Diff line number Diff line change 27
27
import org .enso .shttp .HTTPTestHelperServer ;
28
28
import org .enso .shttp .HybridHTTPServer ;
29
29
import org .enso .shttp .SimpleHttpHandler ;
30
+ import org .enso .testkit .RetryTestRule ;
30
31
import org .junit .AfterClass ;
31
32
import org .junit .BeforeClass ;
33
+ import org .junit .Rule ;
32
34
import org .junit .Test ;
33
35
import scala .Option ;
34
36
import scala .util .Try ;
@@ -41,6 +43,8 @@ public class HttpDownloaderTest {
41
43
private static HybridHTTPServer server ;
42
44
private static ExecutorService serverExecutor ;
43
45
46
+ @ Rule public RetryTestRule retry = new RetryTestRule (3 );
47
+
44
48
@ BeforeClass
45
49
public static void initServer () throws URISyntaxException , IOException {
46
50
serverExecutor = Executors .newSingleThreadExecutor ();
Original file line number Diff line number Diff line change
1
+ package org .enso .testkit ;
2
+
3
+ import org .junit .rules .TestRule ;
4
+ import org .junit .runner .Description ;
5
+ import org .junit .runners .model .Statement ;
6
+
7
+ /**
8
+ * Flaky test specification for JUnit.
9
+ *
10
+ * <p>Inspired by <a href="https://stackoverflow.com/a/8301639/4816269">this SO answer</a>.
11
+ *
12
+ * <p>Use it like this:
13
+ *
14
+ * <pre>
15
+ * public class MyTest {
16
+ * @Rule
17
+ * public RetryTestRule retry = new RetryTestRule(3);
18
+ * @Test
19
+ * public void myTest() {...}
20
+ * }
21
+ * </pre>
22
+ */
23
+ public class RetryTestRule implements TestRule {
24
+ private int retryCount ;
25
+
26
+ public RetryTestRule (int retryCount ) {
27
+ this .retryCount = retryCount ;
28
+ }
29
+
30
+ @ Override
31
+ public Statement apply (Statement base , Description description ) {
32
+ return statement (base , description );
33
+ }
34
+
35
+ private Statement statement (final Statement base , final Description description ) {
36
+ return new Statement () {
37
+ @ Override
38
+ public void evaluate () throws Throwable {
39
+ Throwable caughtThrowable = null ;
40
+
41
+ for (int i = 0 ; i < retryCount ; i ++) {
42
+ try {
43
+ base .evaluate ();
44
+ return ;
45
+ } catch (Throwable t ) {
46
+ caughtThrowable = t ;
47
+ System .err .println (description .getDisplayName () + ": run " + (i + 1 ) + " failed" );
48
+ }
49
+ }
50
+ System .err .println (
51
+ description .getDisplayName () + ": giving up after " + retryCount + " failures" );
52
+ throw caughtThrowable ;
53
+ }
54
+ };
55
+ }
56
+ }
You can’t perform that action at this time.
0 commit comments