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

bugfix: Try to fix Mill flaky test #5661

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package tests.mill

import scala.concurrent.duration.Duration

import scala.meta.internal.metals.ServerCommands
import scala.meta.internal.metals.{BuildInfo => V}

Expand All @@ -12,8 +10,10 @@ import tests.MillServerInitializer
class MillServerCodeLensSuite
extends BaseCodeLensLspSuite("mill-server-lenses", MillServerInitializer) {

override def munitTimeout: Duration = Duration("4min")

/*
* There is some flakiness involved, possibly https://github.com/com-lihaoyi/mill/issues/2826
* We added some timeouts to make sure the test is correctly retried when fetching lenses.
*/
test("run-mill-lens", maxRetry = 3) {
cleanWorkspace()
writeLayout(
Expand All @@ -30,7 +30,7 @@ class MillServerCodeLensSuite
|// no test lense as debug is not supported
|class Foo extends munit.FunSuite {}
|""".stripMargin,
V.scala213,
V.scala3,
V.millVersion,
includeMunit = true,
)
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/src/main/scala/tests/TestingServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ final case class TestingServer(
filename: String,
maxRetries: Int = 4,
): Future[List[l.CodeLens]] = {
Debug.printEnclosing(filename)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain to me what does this thing do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just prints that this method has been invoked together with the filename.

This is where things like 2023.10.06 10:30:46 INFO tests.BaseLspSuite#initialize come from.

val path = toPath(filename)
val uri = path.toURI.toString
val params = new CodeLensParams(new TextDocumentIdentifier(uri))
Expand All @@ -1048,9 +1049,18 @@ final case class TestingServer(
var retries = maxRetries
val codeLenses = Promise[List[l.CodeLens]]()
val handler = { refreshCount: Int =>
scribe.info(s"Refreshing model for $filename")
if (refreshCount > 0)
for {
lenses <- fullServer.codeLens(params).asScala.map(_.asScala)
lenses <- fullServer
.codeLens(params)
.asScala
.map(_.asScala)
.withTimeout(10, util.concurrent.TimeUnit.SECONDS)
.recover { _ =>
scribe.info(s"Timeout for fetching lenses reached for $filename")
Nil
}
} {
if (lenses.nonEmpty) codeLenses.trySuccess(lenses.toList)
else if (retries > 0) {
Expand All @@ -1072,6 +1082,7 @@ final case class TestingServer(
// first compilation, to trigger the handler
_ <- server.compilations.compileFile(path)
lenses <- codeLenses.future
.withTimeout(60, util.concurrent.TimeUnit.SECONDS)
} yield lenses
}

Expand Down
Loading