Skip to content

Commit

Permalink
improvement: Retry code actions in Scala CLI suite
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Oct 10, 2024
1 parent d57cd86 commit 633ccca
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class BaseScalaCLIActionSuite(name: String)
changeFile: String => String = identity,
expectError: Boolean = false,
filterAction: CodeAction => Boolean = _ => true,
retryAction: Int = 0,
)(implicit loc: Location): Unit = {

val path = toPath(fileName)
Expand Down Expand Up @@ -96,6 +97,7 @@ class BaseScalaCLIActionSuite(name: String)
expectError,
filterAction,
overrideLayout = layout,
retryAction,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class ScalaCliActionsSuite
scalaCliOptions = List("--actions", "-S", scalaVersion),
expectNoDiagnostics = false,
selectedActionIndex = 1,
// Scala CLI doesn't publish everything with the normal diagnostics, but later
retryAction = 5,
)

checkScalaCLI(
Expand Down Expand Up @@ -83,6 +85,8 @@ class ScalaCliActionsSuite
scalaCliOptions = List("--actions", "-S", scalaVersion),
expectNoDiagnostics = false,
selectedActionIndex = 1,
// Scala CLI doesn't publish everything with the normal diagnostics, but later
retryAction = 5,
)

checkNoActionScalaCLI(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ abstract class BaseCodeActionLspSuite(
expectError: Boolean = false,
filterAction: CodeAction => Boolean = _ => true,
overrideLayout: Option[String] = None,
retryAction: Int = 0,
)(implicit loc: Location): Unit = {
val scalacOptionsJson =
if (scalacOptions.nonEmpty)
Expand Down Expand Up @@ -88,6 +89,7 @@ abstract class BaseCodeActionLspSuite(
changeFile,
expectError,
filterAction,
retryAction,
)
}

Expand All @@ -105,6 +107,7 @@ abstract class BaseCodeActionLspSuite(
changeFile: String => String = identity,
expectError: Boolean = false,
filterAction: CodeAction => Boolean = _ => true,
retryAction: Int = 0,
)(implicit loc: Location): Unit = {
val files = FileLayout.mapFromString(layout)
val (path, input) = files
Expand All @@ -120,6 +123,24 @@ abstract class BaseCodeActionLspSuite(
if (renamePath.nonEmpty) input.replace("<<", "").replace(">>", "")
else expectedCode

def assertActionsWithRetry(
retry: Int = retryAction
): Future[List[CodeAction]] = {
server
.assertCodeAction(
path,
changeFile(input),
expectedActions,
kind,
filterAction = filterAction,
)
.recoverWith {
case _: Throwable if retry > 0 =>
Thread.sleep(1000)
assertActionsWithRetry(retry - 1)
case _: Throwable if expectError => Future.successful(Nil)
}
}
test(name) {
cleanWorkspace()
for {
Expand All @@ -135,18 +156,7 @@ abstract class BaseCodeActionLspSuite(
path,
changeFile(input).replace("<<", "").replace(">>", ""),
)
codeActions <-
server
.assertCodeAction(
path,
changeFile(input),
expectedActions,
kind,
filterAction = filterAction,
)
.recover {
case _: Throwable if expectError => Nil
}
codeActions <- assertActionsWithRetry()
_ <- client.applyCodeAction(selectedActionIndex, codeActions, server)
_ <- server.didSave(newPath) { _ =>
if (newPath != path)
Expand Down

0 comments on commit 633ccca

Please sign in to comment.