mirror of https://github.com/sbt/sbt.git
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:
parent
2f66304a48
commit
2f5d542965
31
build.sbt
31
build.sbt
|
|
@ -1075,7 +1075,7 @@ lazy val sbtProj = (project in file("sbt"))
|
||||||
.configure(addSbtIO, addSbtCompilerBridge)
|
.configure(addSbtIO, addSbtCompilerBridge)
|
||||||
|
|
||||||
lazy val serverTestProj = (project in file("server-test"))
|
lazy val serverTestProj = (project in file("server-test"))
|
||||||
.dependsOn(sbtProj % "test->test", scriptedSbtReduxProj % "test->test")
|
.dependsOn(sbtProj % "compile->test", scriptedSbtReduxProj % "compile->test")
|
||||||
.settings(
|
.settings(
|
||||||
testedBaseSettings,
|
testedBaseSettings,
|
||||||
crossScalaVersions := Seq(baseScalaVersion),
|
crossScalaVersions := Seq(baseScalaVersion),
|
||||||
|
|
@ -1086,15 +1086,26 @@ lazy val serverTestProj = (project in file("server-test"))
|
||||||
Test / run / connectInput := true,
|
Test / run / connectInput := true,
|
||||||
Test / run / outputStrategy := Some(StdoutOutput),
|
Test / run / outputStrategy := Some(StdoutOutput),
|
||||||
Test / run / fork := true,
|
Test / run / fork := true,
|
||||||
Test / fork := true,
|
Test / sourceGenerators += Def.task {
|
||||||
Test / javaOptions ++= {
|
val rawClasspath =
|
||||||
val cp = (Test / fullClasspathAsJars).value.map(_.data).mkString(java.io.File.pathSeparator)
|
(Compile / fullClasspathAsJars).value.map(_.data).mkString(java.io.File.pathSeparator)
|
||||||
List(
|
val cp =
|
||||||
s"-Dsbt.server.classpath=$cp",
|
if (scala.util.Properties.isWin) rawClasspath.replaceAllLiterally("\\", "\\\\")
|
||||||
s"-Dsbt.server.version=${version.value}",
|
else rawClasspath
|
||||||
s"-Dsbt.server.scala.version=${scalaVersion.value}",
|
val content = {
|
||||||
s"-Dsbt.supershell=false",
|
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
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,10 @@ object RunFromSourceMain {
|
||||||
): Process = {
|
): Process = {
|
||||||
val fo = fo0
|
val fo = fo0
|
||||||
.withWorkingDirectory(workingDirectory)
|
.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 Some(home) => Vector(s"-Dsbt.ivy.home=$home")
|
||||||
case _ => Vector()
|
case _ => Vector()
|
||||||
})
|
}) ++ fo0.runJVMOptions)
|
||||||
implicit val runner = new ForkRun(fo)
|
implicit val runner = new ForkRun(fo)
|
||||||
val options =
|
val options =
|
||||||
Vector(workingDirectory.toString, scalaVersion, sbtVersion, cp.mkString(pathSeparator))
|
Vector(workingDirectory.toString, scalaVersion, sbtVersion, cp.mkString(pathSeparator))
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import java.util.concurrent.{ LinkedBlockingQueue, TimeUnit }
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
import verify._
|
import verify._
|
||||||
import sbt.RunFromSourceMain
|
import sbt.{ ForkOptions, OutputStrategy, RunFromSourceMain }
|
||||||
import sbt.io.IO
|
import sbt.io.IO
|
||||||
import sbt.io.syntax._
|
import sbt.io.syntax._
|
||||||
import sbt.protocol.ClientSocket
|
import sbt.protocol.ClientSocket
|
||||||
|
|
@ -43,18 +43,9 @@ trait AbstractServerTest extends TestSuite[Unit] {
|
||||||
"server-test"
|
"server-test"
|
||||||
)
|
)
|
||||||
temp = base.toFile
|
temp = base.toFile
|
||||||
val classpath = sys.props.get("sbt.server.classpath") match {
|
val classpath = TestProperties.classpath.split(File.pathSeparator).map(new File(_))
|
||||||
case Some(s: String) => s.split(java.io.File.pathSeparator).map(file)
|
val sbtVersion = TestProperties.version
|
||||||
case _ => throw new IllegalStateException("No server classpath was specified.")
|
val scalaVersion = TestProperties.scalaVersion
|
||||||
}
|
|
||||||
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.")
|
|
||||||
}
|
|
||||||
svr = TestServer.get(testDirectory, scalaVersion, sbtVersion, classpath, temp)
|
svr = TestServer.get(testDirectory, scalaVersion, sbtVersion, classpath, temp)
|
||||||
}
|
}
|
||||||
override def tearDownSuite(): Unit = {
|
override def tearDownSuite(): Unit = {
|
||||||
|
|
@ -169,7 +160,12 @@ case class TestServer(
|
||||||
import TestServer.hostLog
|
import TestServer.hostLog
|
||||||
|
|
||||||
hostLog("fork to a new sbt instance")
|
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"
|
lazy val portfile = baseDirectory / "project" / "target" / "active.json"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue