Don't fork server tests

I was seeing some failures in travis ci where the build crashed because
it wasn't able to open a socket. This failure was happening in the
scalatest fork runner so I decided to avoid forking entirely. An
alternative approach would possibly be just to remove the scalatest
framework from the server test project but not forking is nicer anyway.
This commit is contained in:
Ethan Atkins 2020-09-27 09:46:32 -07:00
parent 2f66304a48
commit 2f5d542965
3 changed files with 33 additions and 26 deletions

View File

@ -1075,7 +1075,7 @@ lazy val sbtProj = (project in file("sbt"))
.configure(addSbtIO, addSbtCompilerBridge)
lazy val serverTestProj = (project in file("server-test"))
.dependsOn(sbtProj % "test->test", scriptedSbtReduxProj % "test->test")
.dependsOn(sbtProj % "compile->test", scriptedSbtReduxProj % "compile->test")
.settings(
testedBaseSettings,
crossScalaVersions := Seq(baseScalaVersion),
@ -1086,15 +1086,26 @@ lazy val serverTestProj = (project in file("server-test"))
Test / run / connectInput := true,
Test / run / outputStrategy := Some(StdoutOutput),
Test / run / fork := true,
Test / fork := true,
Test / javaOptions ++= {
val cp = (Test / fullClasspathAsJars).value.map(_.data).mkString(java.io.File.pathSeparator)
List(
s"-Dsbt.server.classpath=$cp",
s"-Dsbt.server.version=${version.value}",
s"-Dsbt.server.scala.version=${scalaVersion.value}",
s"-Dsbt.supershell=false",
)
Test / sourceGenerators += Def.task {
val rawClasspath =
(Compile / fullClasspathAsJars).value.map(_.data).mkString(java.io.File.pathSeparator)
val cp =
if (scala.util.Properties.isWin) rawClasspath.replaceAllLiterally("\\", "\\\\")
else rawClasspath
val content = {
s"""|
|package testpkg
|
|object TestProperties {
| val classpath = "$cp"
| val version = "${version.value}"
| val scalaVersion = "${scalaVersion.value}"
|}
""".stripMargin
}
val file = (Test / target).value / "generated" / "src" / "test" / "scala" / "testpkg" / "TestProperties.scala"
IO.write(file, content)
file :: Nil
},
)

View File

@ -37,10 +37,10 @@ object RunFromSourceMain {
): Process = {
val fo = fo0
.withWorkingDirectory(workingDirectory)
.withRunJVMOptions(sys.props.get("sbt.ivy.home") match {
.withRunJVMOptions((sys.props.get("sbt.ivy.home") match {
case Some(home) => Vector(s"-Dsbt.ivy.home=$home")
case _ => Vector()
})
}) ++ fo0.runJVMOptions)
implicit val runner = new ForkRun(fo)
val options =
Vector(workingDirectory.toString, scalaVersion, sbtVersion, cp.mkString(pathSeparator))

View File

@ -14,7 +14,7 @@ import java.util.concurrent.{ LinkedBlockingQueue, TimeUnit }
import java.util.concurrent.atomic.AtomicBoolean
import verify._
import sbt.RunFromSourceMain
import sbt.{ ForkOptions, OutputStrategy, RunFromSourceMain }
import sbt.io.IO
import sbt.io.syntax._
import sbt.protocol.ClientSocket
@ -43,18 +43,9 @@ trait AbstractServerTest extends TestSuite[Unit] {
"server-test"
)
temp = base.toFile
val classpath = sys.props.get("sbt.server.classpath") match {
case Some(s: String) => s.split(java.io.File.pathSeparator).map(file)
case _ => throw new IllegalStateException("No server classpath was specified.")
}
val sbtVersion = sys.props.get("sbt.server.version") match {
case Some(v: String) => v
case _ => throw new IllegalStateException("No server version was specified.")
}
val scalaVersion = sys.props.get("sbt.server.scala.version") match {
case Some(v: String) => v
case _ => throw new IllegalStateException("No server scala version was specified.")
}
val classpath = TestProperties.classpath.split(File.pathSeparator).map(new File(_))
val sbtVersion = TestProperties.version
val scalaVersion = TestProperties.scalaVersion
svr = TestServer.get(testDirectory, scalaVersion, sbtVersion, classpath, temp)
}
override def tearDownSuite(): Unit = {
@ -169,7 +160,12 @@ case class TestServer(
import TestServer.hostLog
hostLog("fork to a new sbt instance")
val process = RunFromSourceMain.fork(baseDirectory, scalaVersion, sbtVersion, classpath)
val forkOptions =
ForkOptions()
.withOutputStrategy(OutputStrategy.StdoutOutput)
.withRunJVMOptions(Vector("-Dsbt.ci=true", "-Dsbt.io.virtual=false"))
val process =
RunFromSourceMain.fork(forkOptions, baseDirectory, scalaVersion, sbtVersion, classpath)
lazy val portfile = baseDirectory / "project" / "target" / "active.json"