在Sbt 0.13.x中进行分拣和订购测试

时间:2014-07-14 08:14:25

标签: scala migration sbt

以下是为Sbt 0.12.x配置的方式:

parallelExecution in test := false

testGrouping in Test <<= definedTests in Test map { tests =>
  tests.map { test =>
    import Tests._
    import scala.collection.JavaConversions._
    new Group(
      name = test.name,
      tests = Seq(test),
      runPolicy = SubProcess(javaOptions = Seq(
        "-server", "-Xms4096m", "-Xms4096m", "-XX:NewSize=3584m", 
        "-Xss256k", "-XX:+UseG1GC", "-XX:+TieredCompilation",
        "-XX:+UseNUMA", "-XX:+UseCondCardMark", 
        "-XX:-UseBiasedLocking", "-XX:+AlwaysPreTouch") ++
        System.getProperties.toMap.map {
          case (k, v)  => "-D" + k + "=" + v
        }))
  }.sortWith(_.name < _.name)
}

在迁移到Sbt 0.13.x期间,我收到以下错误:

[error] Could not accept connection from test agent: class java.net.SocketException: socket closed
java.net.SocketException: socket closed
    at java.net.DualStackPlainSocketImpl.accept0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketAccept(DualStackPlainSocketImpl.java:131)
    at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:398)
    at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:199)
    at java.net.ServerSocket.implAccept(ServerSocket.java:530)
    at java.net.ServerSocket.accept(ServerSocket.java:498)
    at sbt.ForkTests$$anonfun$mainTestTask$1$Acceptor$2$.run(ForkTests.scala:48)
    at java.lang.Thread.run(Thread.java:745)

迁移变更仅为updates in sbt & plugin versions

在Sbt 0.13.x中是否还有其他方法可以分析和排序测试以克服该异常?

2 个答案:

答案 0 :(得分:1)

在Linux和Mac OS上运行良好。

在Windows上出现错误,因为类路径长度限制导致在System.err中阻止启动测试代理实例并出现以下错误:

Error: Could not find or load main class sbt.ForkMain

答案 1 :(得分:1)

当我将Scala仓库转移到sbt版本sbt.version = 1.3.8(以前是1.2.8还可以)时,我也遇到了这个错误。奇怪地,在我的Mac上工作正常,但在teamcity linux build agent上失败。

修正是要设置

  fork := false,

在build.sbt中。

不知道为什么仓库以前将它设置为fork:= true(猜测它是从其他地方剪切/粘贴的,因为在此仓库中没有强烈的理由),但是此更改解决了问题。现在在我的Mac上本地运行的速度也快了几秒钟。

请参阅此处了解背景 https://www.scala-sbt.org/1.0/docs/Forking.html