简体   繁体   English

SBT测试中的奇怪异常

[英]Strange exception in SBT test

I am facing an issue with SBT (version 0.13.9). 我遇到SBT(0.13.9版)问题。 One of my ScalaTest tests fails not deterministic with EOFException . 我的一个ScalaTest测试无法通过EOFException确定性失败。

Stack trace: 堆栈跟踪:

Exception in thread "Thread-155" Exception in thread "Thread-159" java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2601)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1319)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at sbt.React.react(ForkTests.scala:114)
at sbt.ForkTests$$anonfun$mainTestTask$1$Acceptor$2$.run(ForkTests.scala:74)
at java.lang.Thread.run(Thread.java:745)

java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2601)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1319)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at org.scalatest.tools.Framework$ScalaTestRunner$Skeleton$1$React.react(Framework.scala:953)
at org.scalatest.tools.Framework$ScalaTestRunner$Skeleton$1.run(Framework.scala:942)
at java.lang.Thread.run(Thread.java:745)

sbt.ForkMain 59974 failed with exit code 134

I don't see any JVM logs or thread dumps. 我没有看到任何JVM日志或线程转储。

SBT single thread or multi threaded tests forks the JVM and if the host name is not resolved it just fails with this error message. SBT单线程或多线程测试会分叉JVM,并且如果主机名未解析,它将失败并显示此错误消息。 If you look at the logs in the tests, you might see 如果查看测试中的日志,可能会看到

Uncaught exception when running tests: java.net.ConnectException: Operation timed out 运行测试时未捕获的异常:java.net.ConnectException:操作超时

So the easy way to resolve this is to add your hostname to the /etc/hosts and map it to localhost something like this 因此,解决此问题的简单方法是将您的主机名添加到/ etc / hosts并将其映射到localhost,如下所示

::1 localhost blahblah :: 1本地主机blahblah

This should resolve the issue. 这样可以解决问题。

Almost certainly this is related to the Java classpath being too long when invoking sbt.ForkMain in certain linux distros. 几乎可以肯定,这与某些Linux发行版中调用sbt.ForkMain时Java类路径太长有关。 To avoid this I added 为了避免这种情况,我添加了

javaOptions in Test ++= Seq("-Xms1G","-XX:+CMSClassUnloadingEnabled","-XX:+UseConcMarkSweepGC")

to the build.sbt file. build.sbt文件。 I reckon CMSClassUnloadingEnabled is where the magic happens. 我认为CMSClassUnloadingEnabled是发生魔术的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM