mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 01:21:33 +03:00
Declare HTTPDownloaderTest as flaky (#9339)
`HTTPDownloaderTest` failed recently transiently. Let's declare it as flaky.
This commit is contained in:
parent
6bf37b3d17
commit
af73768d14
@ -1092,9 +1092,11 @@ lazy val testkit = project
|
||||
.settings(
|
||||
frgaalJavaCompilerSetting,
|
||||
libraryDependencies ++= Seq(
|
||||
"org.apache.commons" % "commons-lang3" % commonsLangVersion,
|
||||
"commons-io" % "commons-io" % commonsIoVersion,
|
||||
"org.scalatest" %% "scalatest" % scalatestVersion
|
||||
"org.apache.commons" % "commons-lang3" % commonsLangVersion,
|
||||
"commons-io" % "commons-io" % commonsIoVersion,
|
||||
"org.scalatest" %% "scalatest" % scalatestVersion,
|
||||
"junit" % "junit" % junitVersion,
|
||||
"com.github.sbt" % "junit-interface" % junitIfVersion
|
||||
)
|
||||
)
|
||||
|
||||
@ -2551,6 +2553,7 @@ lazy val downloader = (project in file("lib/scala/downloader"))
|
||||
)
|
||||
.dependsOn(cli)
|
||||
.dependsOn(`http-test-helper`)
|
||||
.dependsOn(testkit % Test)
|
||||
|
||||
lazy val `edition-updater` = project
|
||||
.in(file("lib/scala/edition-updater"))
|
||||
|
@ -27,8 +27,10 @@ import org.enso.cli.task.TaskProgress;
|
||||
import org.enso.shttp.HTTPTestHelperServer;
|
||||
import org.enso.shttp.HybridHTTPServer;
|
||||
import org.enso.shttp.SimpleHttpHandler;
|
||||
import org.enso.testkit.RetryTestRule;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import scala.Option;
|
||||
import scala.util.Try;
|
||||
@ -41,6 +43,8 @@ public class HttpDownloaderTest {
|
||||
private static HybridHTTPServer server;
|
||||
private static ExecutorService serverExecutor;
|
||||
|
||||
@Rule public RetryTestRule retry = new RetryTestRule(3);
|
||||
|
||||
@BeforeClass
|
||||
public static void initServer() throws URISyntaxException, IOException {
|
||||
serverExecutor = Executors.newSingleThreadExecutor();
|
||||
|
@ -0,0 +1,74 @@
|
||||
package org.enso.testkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
/**
|
||||
* Flaky test specification for JUnit.
|
||||
*
|
||||
* <p>Inspired by <a href="https://stackoverflow.com/a/8301639/4816269">this SO answer</a>.
|
||||
*
|
||||
* <p>Use it like this:
|
||||
*
|
||||
* <pre>
|
||||
* public class MyTest {
|
||||
* @Rule
|
||||
* public RetryTestRule retry = new RetryTestRule(3);
|
||||
* @Test
|
||||
* public void myTest() {...}
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
public class RetryTestRule implements TestRule {
|
||||
private int retryCount;
|
||||
|
||||
public RetryTestRule(int retryCount) {
|
||||
this.retryCount = retryCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
return statement(base, description);
|
||||
}
|
||||
|
||||
private Statement statement(final Statement base, final Description description) {
|
||||
return new Statement() {
|
||||
@Override
|
||||
public void evaluate() {
|
||||
List<Throwable> caughtThrowables = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < retryCount; i++) {
|
||||
try {
|
||||
base.evaluate();
|
||||
return;
|
||||
} catch (Throwable t) {
|
||||
caughtThrowables.add(t);
|
||||
System.err.println(
|
||||
description.getClassName()
|
||||
+ "."
|
||||
+ description.getDisplayName()
|
||||
+ ": run "
|
||||
+ (i + 1)
|
||||
+ " failed");
|
||||
}
|
||||
}
|
||||
var err =
|
||||
new AssertionError(
|
||||
description.getDisplayName() + ": giving up after " + retryCount + " failures");
|
||||
for (var t : caughtThrowables) {
|
||||
Throwable n = err;
|
||||
while (n.getCause() != null) {
|
||||
n = n.getCause();
|
||||
}
|
||||
n.initCause(t);
|
||||
}
|
||||
System.err.println(
|
||||
description.getDisplayName() + ": giving up after " + retryCount + " failures");
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user