Skip to content

Commit cd3bd51

Browse files
authored
Retry some of the occasionally flaky tests when failing on the CI (#3320)
1 parent 7846f80 commit cd3bd51

12 files changed

+1087
-1022
lines changed

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

Lines changed: 67 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,74 +1907,78 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
19071907
}
19081908

19091909
test("BSP respects JAVA_HOME") {
1910-
val javaVersion = "22"
1911-
val inputs = TestInputs(os.rel / "check-java.sc" ->
1912-
s"""assert(System.getProperty("java.version").startsWith("$javaVersion"))
1913-
|println(System.getProperty("java.home"))""".stripMargin)
1914-
inputs.fromRoot { root =>
1915-
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
1916-
val java22Home =
1917-
os.Path(
1918-
os.proc(TestUtil.cs, "java-home", "--jvm", s"zulu:$javaVersion").call().out.trim(),
1919-
os.pwd
1920-
)
1921-
os.proc(TestUtil.cli, "setup-ide", "check-java.sc")
1922-
.call(cwd = root, env = Map("JAVA_HOME" -> java22Home.toString()))
1923-
val ideOptionsPath = root / Constants.workspaceDirName / "ide-options-v2.json"
1924-
expect(ideOptionsPath.toNIO.toFile.exists())
1925-
val ideEnvsPath = root / Constants.workspaceDirName / "ide-envs.json"
1926-
expect(ideEnvsPath.toNIO.toFile.exists())
1927-
val jsonOptions = List("--json-options", ideOptionsPath.toString)
1928-
val envOptions = List("--envs-file", ideEnvsPath.toString)
1929-
withBsp(inputs, Seq("."), bspOptions = jsonOptions ++ envOptions, reuseRoot = Some(root)) {
1930-
(_, _, remoteServer) =>
1931-
async {
1932-
val targets = await(remoteServer.workspaceBuildTargets().asScala)
1933-
.getTargets.asScala
1934-
.filter(!_.getId.getUri.contains("-test"))
1935-
.map(_.getId())
1936-
val compileResult =
1937-
await(remoteServer.buildTargetCompile(new b.CompileParams(targets.asJava)).asScala)
1938-
expect(compileResult.getStatusCode == b.StatusCode.OK)
1939-
val runResult =
1940-
await(remoteServer.buildTargetRun(new b.RunParams(targets.head)).asScala)
1941-
expect(runResult.getStatusCode == b.StatusCode.OK)
1942-
}
1910+
TestUtil.retryOnCi() {
1911+
val javaVersion = "22"
1912+
val inputs = TestInputs(os.rel / "check-java.sc" ->
1913+
s"""assert(System.getProperty("java.version").startsWith("$javaVersion"))
1914+
|println(System.getProperty("java.home"))""".stripMargin)
1915+
inputs.fromRoot { root =>
1916+
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
1917+
val java22Home =
1918+
os.Path(
1919+
os.proc(TestUtil.cs, "java-home", "--jvm", s"zulu:$javaVersion").call().out.trim(),
1920+
os.pwd
1921+
)
1922+
os.proc(TestUtil.cli, "setup-ide", "check-java.sc")
1923+
.call(cwd = root, env = Map("JAVA_HOME" -> java22Home.toString()))
1924+
val ideOptionsPath = root / Constants.workspaceDirName / "ide-options-v2.json"
1925+
expect(ideOptionsPath.toNIO.toFile.exists())
1926+
val ideEnvsPath = root / Constants.workspaceDirName / "ide-envs.json"
1927+
expect(ideEnvsPath.toNIO.toFile.exists())
1928+
val jsonOptions = List("--json-options", ideOptionsPath.toString)
1929+
val envOptions = List("--envs-file", ideEnvsPath.toString)
1930+
withBsp(inputs, Seq("."), bspOptions = jsonOptions ++ envOptions, reuseRoot = Some(root)) {
1931+
(_, _, remoteServer) =>
1932+
async {
1933+
val targets = await(remoteServer.workspaceBuildTargets().asScala)
1934+
.getTargets.asScala
1935+
.filter(!_.getId.getUri.contains("-test"))
1936+
.map(_.getId())
1937+
val compileResult =
1938+
await(remoteServer.buildTargetCompile(new b.CompileParams(targets.asJava)).asScala)
1939+
expect(compileResult.getStatusCode == b.StatusCode.OK)
1940+
val runResult =
1941+
await(remoteServer.buildTargetRun(new b.RunParams(targets.head)).asScala)
1942+
expect(runResult.getStatusCode == b.StatusCode.OK)
1943+
}
1944+
}
19431945
}
19441946
}
19451947
}
19461948

19471949
test("BSP respects --java-home") {
1948-
val javaVersion = "22"
1949-
val inputs = TestInputs(os.rel / "check-java.sc" ->
1950-
s"""assert(System.getProperty("java.version").startsWith("$javaVersion"))
1951-
|println(System.getProperty("java.home"))""".stripMargin)
1952-
inputs.fromRoot { root =>
1953-
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
1954-
val java22Home =
1955-
os.Path(
1956-
os.proc(TestUtil.cs, "java-home", "--jvm", s"zulu:$javaVersion").call().out.trim(),
1957-
os.pwd
1958-
)
1959-
os.proc(TestUtil.cli, "setup-ide", "check-java.sc", "--java-home", java22Home.toString())
1960-
.call(cwd = root)
1961-
val ideOptionsPath = root / Constants.workspaceDirName / "ide-options-v2.json"
1962-
expect(ideOptionsPath.toNIO.toFile.exists())
1963-
val jsonOptions = List("--json-options", ideOptionsPath.toString)
1964-
withBsp(inputs, Seq("."), bspOptions = jsonOptions, reuseRoot = Some(root)) {
1965-
(_, _, remoteServer) =>
1966-
async {
1967-
val targets = await(remoteServer.workspaceBuildTargets().asScala)
1968-
.getTargets.asScala
1969-
.filter(!_.getId.getUri.contains("-test"))
1970-
.map(_.getId())
1971-
val compileResult =
1972-
await(remoteServer.buildTargetCompile(new b.CompileParams(targets.asJava)).asScala)
1973-
expect(compileResult.getStatusCode == b.StatusCode.OK)
1974-
val runResult =
1975-
await(remoteServer.buildTargetRun(new b.RunParams(targets.head)).asScala)
1976-
expect(runResult.getStatusCode == b.StatusCode.OK)
1977-
}
1950+
TestUtil.retryOnCi() {
1951+
val javaVersion = "22"
1952+
val inputs = TestInputs(os.rel / "check-java.sc" ->
1953+
s"""assert(System.getProperty("java.version").startsWith("$javaVersion"))
1954+
|println(System.getProperty("java.home"))""".stripMargin)
1955+
inputs.fromRoot { root =>
1956+
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
1957+
val java22Home =
1958+
os.Path(
1959+
os.proc(TestUtil.cs, "java-home", "--jvm", s"zulu:$javaVersion").call().out.trim(),
1960+
os.pwd
1961+
)
1962+
os.proc(TestUtil.cli, "setup-ide", "check-java.sc", "--java-home", java22Home.toString())
1963+
.call(cwd = root)
1964+
val ideOptionsPath = root / Constants.workspaceDirName / "ide-options-v2.json"
1965+
expect(ideOptionsPath.toNIO.toFile.exists())
1966+
val jsonOptions = List("--json-options", ideOptionsPath.toString)
1967+
withBsp(inputs, Seq("."), bspOptions = jsonOptions, reuseRoot = Some(root)) {
1968+
(_, _, remoteServer) =>
1969+
async {
1970+
val targets = await(remoteServer.workspaceBuildTargets().asScala)
1971+
.getTargets.asScala
1972+
.filter(!_.getId.getUri.contains("-test"))
1973+
.map(_.getId())
1974+
val compileResult =
1975+
await(remoteServer.buildTargetCompile(new b.CompileParams(targets.asJava)).asScala)
1976+
expect(compileResult.getStatusCode == b.StatusCode.OK)
1977+
val runResult =
1978+
await(remoteServer.buildTargetRun(new b.RunParams(targets.head)).asScala)
1979+
expect(runResult.getStatusCode == b.StatusCode.OK)
1980+
}
1981+
}
19781982
}
19791983
}
19801984
}

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

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -175,87 +175,89 @@ class ConfigTests extends ScalaCliSuite {
175175

176176
if (TestUtil.isNativeCli)
177177
test(s"Create a PGP key with external JVM process, java version too low") {
178-
TestInputs().fromRoot { root =>
179-
val configFile = {
180-
val dir = root / "config"
181-
os.makeDir.all(dir, perms = if (Properties.isWin) null else "rwx------")
182-
dir / "config.json"
183-
}
184-
185-
val java8Home =
186-
os.Path(os.proc(TestUtil.cs, "java-home", "--jvm", "zulu:8").call().out.trim(), os.pwd)
187-
188-
val extraEnv = Map(
189-
"JAVA_HOME" -> java8Home.toString,
190-
"PATH" -> ((java8Home / "bin").toString + File.pathSeparator + System.getenv("PATH")),
191-
"SCALA_CLI_CONFIG" -> configFile.toString
192-
)
193-
194-
val pgpCreated = os.proc(
195-
TestUtil.cli,
196-
"--power",
197-
"config",
198-
"--create-pgp-key",
199-
"--email",
200-
201-
"--pgp-password",
202-
"none",
203-
"--force-jvm-signing-cli",
204-
"-v",
205-
"-v",
206-
"-v"
207-
)
208-
.call(cwd = root, env = extraEnv, mergeErrIntoOut = true)
178+
TestUtil.retryOnCi() {
179+
TestInputs().fromRoot { root =>
180+
val configFile = {
181+
val dir = root / "config"
182+
os.makeDir.all(dir, perms = if (Properties.isWin) null else "rwx------")
183+
dir / "config.json"
184+
}
185+
186+
val java8Home =
187+
os.Path(os.proc(TestUtil.cs, "java-home", "--jvm", "zulu:8").call().out.trim(), os.pwd)
188+
189+
val extraEnv = Map(
190+
"JAVA_HOME" -> java8Home.toString,
191+
"PATH" -> ((java8Home / "bin").toString + File.pathSeparator + System.getenv("PATH")),
192+
"SCALA_CLI_CONFIG" -> configFile.toString
193+
)
194+
195+
val pgpCreated = os.proc(
196+
TestUtil.cli,
197+
"--power",
198+
"config",
199+
"--create-pgp-key",
200+
"--email",
201+
202+
"--pgp-password",
203+
"none",
204+
"--force-jvm-signing-cli",
205+
"-v",
206+
"-v",
207+
"-v"
208+
)
209+
.call(cwd = root, env = extraEnv, mergeErrIntoOut = true)
209210

210-
val javaCommandLine = pgpCreated.out.text()
211-
.linesIterator
212-
.dropWhile(!_.equals(" Running")).slice(1, 2)
213-
.toSeq
211+
val javaCommandLine = pgpCreated.out.text()
212+
.linesIterator
213+
.dropWhile(!_.equals(" Running")).slice(1, 2)
214+
.toSeq
214215

215-
expect(javaCommandLine.nonEmpty)
216-
expect(javaCommandLine.head.contains("17"))
216+
expect(javaCommandLine.nonEmpty)
217+
expect(javaCommandLine.head.contains("17"))
217218

218-
val passwordInConfig = os.proc(TestUtil.cli, "--power", "config", "pgp.secret-key-password")
219-
.call(cwd = root, env = extraEnv, stderr = os.Pipe)
220-
expect(passwordInConfig.out.text().isEmpty())
219+
val passwordInConfig =
220+
os.proc(TestUtil.cli, "--power", "config", "pgp.secret-key-password")
221+
.call(cwd = root, env = extraEnv, stderr = os.Pipe)
222+
expect(passwordInConfig.out.text().isEmpty())
221223

222-
val secretKey = os.proc(TestUtil.cli, "--power", "config", "pgp.secret-key")
223-
.call(cwd = root, env = extraEnv, stderr = os.Pipe)
224-
.out.trim()
225-
val rawPublicKey =
226-
os.proc(TestUtil.cli, "--power", "config", "pgp.public-key", "--password-value")
224+
val secretKey = os.proc(TestUtil.cli, "--power", "config", "pgp.secret-key")
227225
.call(cwd = root, env = extraEnv, stderr = os.Pipe)
228226
.out.trim()
229-
230-
val tmpFile = root / "test-file"
231-
val tmpFileAsc = root / "test-file.asc"
232-
os.write(tmpFile, "Hello")
233-
234-
val q = "\""
235-
236-
def maybeEscape(arg: String): String =
237-
if (Properties.isWin) q + arg + q
238-
else arg
239-
240-
os.proc(
241-
TestUtil.cli,
242-
"--power",
243-
"pgp",
244-
"sign",
245-
"--secret-key",
246-
maybeEscape(secretKey),
247-
tmpFile
248-
).call(cwd = root, stdin = os.Inherit, stdout = os.Inherit, env = extraEnv)
249-
250-
val pubKeyFile = root / "key.pub"
251-
os.write(pubKeyFile, rawPublicKey)
252-
val verifyResult =
253-
os.proc(TestUtil.cli, "--power", "pgp", "verify", "--key", pubKeyFile, tmpFileAsc)
254-
.call(cwd = root, env = extraEnv, mergeErrIntoOut = true)
255-
256-
expect(verifyResult.out.text().contains("valid signature"))
227+
val rawPublicKey =
228+
os.proc(TestUtil.cli, "--power", "config", "pgp.public-key", "--password-value")
229+
.call(cwd = root, env = extraEnv, stderr = os.Pipe)
230+
.out.trim()
231+
232+
val tmpFile = root / "test-file"
233+
val tmpFileAsc = root / "test-file.asc"
234+
os.write(tmpFile, "Hello")
235+
236+
val q = "\""
237+
238+
def maybeEscape(arg: String): String =
239+
if (Properties.isWin) q + arg + q
240+
else arg
241+
242+
os.proc(
243+
TestUtil.cli,
244+
"--power",
245+
"pgp",
246+
"sign",
247+
"--secret-key",
248+
maybeEscape(secretKey),
249+
tmpFile
250+
).call(cwd = root, stdin = os.Inherit, stdout = os.Inherit, env = extraEnv)
251+
252+
val pubKeyFile = root / "key.pub"
253+
os.write(pubKeyFile, rawPublicKey)
254+
val verifyResult =
255+
os.proc(TestUtil.cli, "--power", "pgp", "verify", "--key", pubKeyFile, tmpFileAsc)
256+
.call(cwd = root, env = extraEnv, mergeErrIntoOut = true)
257+
258+
expect(verifyResult.out.text().contains("valid signature"))
259+
}
257260
}
258-
259261
}
260262

261263
def createDefaultPgpKeyTest(pgpPasswordOption: String): Unit = {

0 commit comments

Comments
 (0)