sbt test fails due to "Forked test harness failed"

Viewed 592

I've got a Scala project which I'm building with sbt. When running sbt test, the tests themselves pass, but then the command fails with "Forked test harness failed: java.io.EOFException".

The build.sbt file does not specify fork in Test.

Example of the error it fails with after running sbt test:

[info] Run completed in 5 seconds, 494 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[error] Error during tests:
[error]     Forked test harness failed: java.io.EOFException
[error]     at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2959)
[error]     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1539)
[error]     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:430)
[error]     at sbt.React.react(ForkTests.scala:177)
[error]     at sbt.ForkTests$Acceptor$1$.run(ForkTests.scala:108)
[error]     at java.lang.Thread.run(Thread.java:748)
[error] (serverTests / Test / test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 14 s, completed Mar 12, 2020 4:35:26 PM

Minimal example of test which fails:

package com.example

import akka.http.scaladsl.testkit.ScalatestRouteTest
import org.scalatest.FreeSpecLike

class ForkedTestHarnessFailedForNoReasonSpec extends FreeSpecLike with ScalatestRouteTest {
  "This test" - {
    "should not fail" in {
      assert("Foo" == "Foo")
    }
  }
}

What does this error indicate and how should one resolve it?

1 Answers

The cause in my case was that AKKA is shutting down JVM on coordinated shutdown. Put this to your test config (src/test/resources/reference.conf in my case):

akka.coordinated-shutdown.exit-jvm = off
Related