Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry example integration tests that didn't finish after 5 minutes #3125

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions example/src/mill/integration/ExampleTestSuite.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package mill.example
import mill.integration.{BashTokenizer, IntegrationTestSuite}
import utest._
import mill.util.Util
import utest._

import java.util.concurrent.{Executors, TimeoutException}
import scala.annotation.tailrec
import scala.concurrent.duration.DurationInt
import scala.util.chaining.scalaUtilChainingOps

/**
Expand Down Expand Up @@ -46,15 +49,40 @@ object ExampleTestSuite extends IntegrationTestSuite {
val tests: Tests = Tests {
val workspaceRoot = initWorkspace()

val testTimeout = 5.minutes

// Integration tests sometime hang on CI
// The idea is to just abort and retry them after a reasonable amount of time
@tailrec def retryOnTimeout[T](n: Int)(body: => T): T = {

// We use Java Future here, as it supports cancellation
val executor = Executors.newFixedThreadPool(1)
val fut = executor.submit { () => body }

try fut.get(testTimeout.length, testTimeout.unit)
catch {
case e: TimeoutException =>
fut.cancel(true)
if (n > 0) {
Console.err.println(s"Timeout occurred (${testTimeout}). Retrying...")
retryOnTimeout(n - 1)(body)
} else throw e
}

}

test("exampleUsage") {
try {
val parsed = upickle.default.read[Seq[(String, String)]](sys.env("MILL_EXAMPLE_PARSED"))
val usageComment = parsed.collect { case ("example", txt) => txt }.mkString("\n\n")
val commandBlocks = ("\n" + usageComment.trim).split("\n> ").filter(_.nonEmpty)
def body = {
lefou marked this conversation as resolved.
Show resolved Hide resolved
val parsed = upickle.default.read[Seq[(String, String)]](sys.env("MILL_EXAMPLE_PARSED"))
val usageComment = parsed.collect { case ("example", txt) => txt }.mkString("\n\n")
val commandBlocks = ("\n" + usageComment.trim).split("\n> ").filter(_.nonEmpty)

for (commandBlock <- commandBlocks) processCommandBlock(workspaceRoot, commandBlock)
for (commandBlock <- commandBlocks) processCommandBlock(workspaceRoot, commandBlock)

if (integrationTestMode != "fork") evalStdout("shutdown")
if (integrationTestMode != "fork") evalStdout("shutdown")
}
retryOnTimeout(3)(body)
} finally {
try os.remove.all(workspaceRoot / "out")
catch { case e: Throwable => /*do nothing*/ }
Expand Down