Skip to content

Commit 1d6bad3

Browse files
Add retry logic to Bloop termination tests
1 parent 999633a commit 1d6bad3

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -306,21 +306,22 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String])
306306
def testScalaTermination(
307307
currentBloopVersion: String,
308308
expectedBloopVersionAfterScalaCliRun: String
309-
) = {
310-
def runBloop(args: String*) =
311-
os.proc(TestUtil.cs, "launch", s"bloop-jvm:$currentBloopVersion", "--", args)
312-
313-
def runScalaCli(args: String*) = os.proc(TestUtil.cli, args)
314-
315-
runBloop("exit").call()
316-
runBloop("about").call(stdout = os.Inherit, stderr = os.Inherit)
317-
runScalaCli("bloop", "start", "-v", "-v", "-v").call(
318-
stdout = os.Inherit,
319-
stderr = os.Inherit
320-
)
321-
val versionLine = runBloop("about").call().out.lines()(0)
322-
expect(versionLine == "bloop v" + expectedBloopVersionAfterScalaCliRun)
323-
}
309+
): Unit =
310+
TestUtil.retry() {
311+
def runBloop(args: String*) =
312+
os.proc(TestUtil.cs, "launch", s"bloop-jvm:$currentBloopVersion", "--", args)
313+
314+
def runScalaCli(args: String*) = os.proc(TestUtil.cli, args)
315+
316+
runBloop("exit").call()
317+
runBloop("about").call(stdout = os.Inherit, stderr = os.Inherit)
318+
runScalaCli("bloop", "start", "-v", "-v", "-v").call(
319+
stdout = os.Inherit,
320+
stderr = os.Inherit
321+
)
322+
val versionLine = runBloop("about").call().out.lines()(0)
323+
expect(versionLine == "bloop v" + expectedBloopVersionAfterScalaCliRun)
324+
}
324325

325326
test("scala-cli terminates incompatible bloop") {
326327
testScalaTermination(Constants.oldBloopVersion, Constants.bloopVersion)

modules/integration/src/test/scala/scala/cli/integration/TestUtil.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import java.io.File
44
import java.util.concurrent.atomic.AtomicInteger
55
import java.util.concurrent.{ExecutorService, Executors, ScheduledExecutorService, ThreadFactory}
66

7+
import scala.annotation.tailrec
8+
import scala.concurrent.duration.{DurationInt, FiniteDuration}
79
import scala.util.Properties
810

911
object TestUtil {
@@ -81,4 +83,26 @@ object TestUtil {
8183
def normalizeUri(uri: String): String =
8284
if (uri.startsWith("file:///")) "file:/" + uri.stripPrefix("file:///")
8385
else uri
86+
87+
def retry[T](
88+
maxAttempts: Int = 3,
89+
waitDuration: FiniteDuration = 5.seconds
90+
)(
91+
run: => T
92+
): T = {
93+
@tailrec
94+
def helper(count: Int): T =
95+
try run
96+
catch {
97+
case t: Throwable =>
98+
if (count >= maxAttempts)
99+
throw new Exception(t)
100+
else {
101+
System.err.println(s"Caught $t, trying again in $waitDuration")
102+
Thread.sleep(waitDuration.toMillis)
103+
helper(count + 1)
104+
}
105+
}
106+
helper(1)
107+
}
84108
}

0 commit comments

Comments
 (0)