Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sbt reports success when forked test suite fails with an exception #2442

Closed
smarter opened this issue Feb 4, 2016 · 9 comments
Closed

sbt reports success when forked test suite fails with an exception #2442

smarter opened this issue Feb 4, 2016 · 9 comments

Comments

@smarter
Copy link
Contributor

smarter commented Feb 4, 2016

See https://scala-ci.typesafe.com/job/dotty-master-validate-junit/1000/console for an example:

Internal error when running tests: java.lang.OutOfMemoryError: Java heap space
Exception in thread "Thread-7" java.io.EOFException
    at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2601)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1319)
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1707)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1345)
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1707)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1345)
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1707)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1345)
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1707)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1345)
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1707)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1345)
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1707)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1345)
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1707)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1345)
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1707)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1345)
    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)
[info] Passed: Total 8, Failed 0, Errors 0, Passed 8
[success] Total time: 1721 s, completed Feb 4, 2016 8:53:52 PM
@SethTisue
Copy link
Member

this makes me a bit nervous about switching scala/scala PR validation from ant to sbt, since sbt will be running some tests forked. did you do something special to work around this for Dotty?

@smarter
Copy link
Contributor Author

smarter commented Feb 5, 2016

No, I just fixed the underlying issue that led to all these OutOfMemoryErrors. This looks like something that can only really be fixed in sbt itself.

@smarter
Copy link
Contributor Author

smarter commented Feb 5, 2016

Note that this should be pretty rare: it happens when the test suite itself fails with an exception, not when a test fails with an exception.

@eed3si9n
Copy link
Member

eed3si9n commented Feb 5, 2016

There was similar report with ScalaTest #1890 / scalatest/scalatest#432.
Not sure what they did (maybe scalatest/scalatest@a3cf999) but ScalaTest 2.2.6 apparently fixed it.

@smarter
Copy link
Contributor Author

smarter commented Feb 5, 2016

SBT does not deal with exceptions in threads correctly, see:

object Acceptor extends Runnable {
val resultsAcc = mutable.Map.empty[String, SuiteResult]
lazy val result = TestOutput(overall(resultsAcc.values.map(_.result)), resultsAcc.toMap, Iterable.empty)
def run() {
val socket =
try {
server.accept()
} catch {
case e: java.net.SocketException =>
log.error("Could not accept connection from test agent: " + e.getClass + ": " + e.getMessage)
log.trace(e)
server.close()
return
}
val os = new ObjectOutputStream(socket.getOutputStream)
// Must flush the header that the constructor writes, otherwise the ObjectInputStream on the other end may block indefinitely
os.flush()
val is = new ObjectInputStream(socket.getInputStream)
try {
val config = new ForkConfiguration(log.ansiCodesSupported, parallel)
os.writeObject(config)
val taskdefs = opts.tests.map(t => new TaskDef(t.name, forkFingerprint(t.fingerprint), t.explicitlySpecified, t.selectors))
os.writeObject(taskdefs.toArray)
os.writeInt(runners.size)
for ((testFramework, mainRunner) <- runners) {
os.writeObject(testFramework.implClassNames.toArray)
os.writeObject(mainRunner.args)
os.writeObject(mainRunner.remoteArgs)
}
os.flush()
new React(is, os, log, opts.testListeners, resultsAcc).react()
} finally {
is.close(); os.close(); socket.close()
}
}
}

Acceptor is an instance of Runnable, in its run method you do not catch any exception, which mean that if one occurs, the thread dies, but nothing will be reported to the caller because you're just using Thread#run and Thread#join which don't report anything about how a Thread died.
I don't know much about Java concurrency but I guess you could use https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.UncaughtExceptionHandler.html

@parkan
Copy link

parkan commented Apr 29, 2016

Seeing this with copycat + sbt as well

https://circleci.com/gh/mediachain/mediachain/48

Definitely doesn't seem like the correct behavior

@kevinmeredith
Copy link

but ScalaTest 2.2.6 apparently fixed it.

Does this gist indicate its success, @eed3si9n?

@eed3si9n
Copy link
Member

@kevinmeredith Reading this issue over today, I now think #1890 is unrelated.
As @smarter wrote:

it happens when the test suite itself fails with an exception, not when a test fails with an exception.

@eed3si9n eed3si9n added this to the 0.13.13 milestone Aug 31, 2016
eed3si9n added a commit to eed3si9n/sbt that referenced this issue Aug 31, 2016
eed3si9n added a commit to eed3si9n/sbt that referenced this issue Aug 31, 2016
@dwijnand dwijnand self-assigned this Sep 2, 2016
dwijnand pushed a commit to dwijnand/sbt that referenced this issue Sep 2, 2016
dwijnand pushed a commit to dwijnand/sbt that referenced this issue Sep 2, 2016
dwijnand pushed a commit to dwijnand/sbt that referenced this issue Sep 2, 2016
@dwijnand
Copy link
Member

dwijnand commented Sep 5, 2016

Fixed in #2730 by @eed3si9n

@dwijnand dwijnand closed this as completed Sep 5, 2016
@dwijnand dwijnand removed their assignment Jan 13, 2017
eed3si9n added a commit to eed3si9n/sbt that referenced this issue Jan 15, 2017
Fail when the forked test harness fails using NonFatal
Fixes sbt#2442/sbt#2722

Add another fork-uncaught scripted test
Originally from https://github.com/retronym/sbt-test-fork-swallows-error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants