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

Exception thrown by forked test framework swallowed #2722

Closed
retronym opened this issue Aug 31, 2016 · 6 comments
Closed

Exception thrown by forked test framework swallowed #2722

retronym opened this issue Aug 31, 2016 · 6 comments
Assignees
Milestone

Comments

@retronym
Copy link
Member

retronym commented Aug 31, 2016

steps

Clone https://github.com/retronym/sbt-test-fork-swallows-error and follow instructions in the README.

sbt> test
[error] Uncaught exception when running tests: java.lang.Throwable
[trace] Stack trace suppressed: run last test:test for the full output.
Exception in thread "Thread-4" java.io.EOFException
    at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2626)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1321)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
    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)
[success] Total time: 0 s, completed 31/08/2016 2:36:09 PM

problem

The exception thrown by the tasks method of the Runner is logged to console, shipped over the wire to the host SBT process, logged again, but the task result is still success.

expectation

The test task should fail.

notes

Discovered in the scala/scala SBT build which uses the partest implementation of the SBT test interface.

@eed3si9n eed3si9n added the Bug label Aug 31, 2016
@eed3si9n
Copy link
Member

Thanks for the repro project. Probably a duplicate of #2442

@retronym
Copy link
Member Author

I've been unable to come up with a workaround. How could I assert that >0 tests were executed?

@eed3si9n
Copy link
Member

According to #2442 (comment) it's a bug in sbt.
There's an if expression that checks >0 tests are about to get executed here -

if (opts.tests.isEmpty)
constant(TestOutput(TestResult.Passed, Map.empty[String, SuiteResult], Iterable.empty))
else
mainTestTask(runners, opts, classpath, fork, log, config.parallel).tagw(config.tags: _*)

@retronym
Copy link
Member Author

retronym commented Aug 31, 2016

This can be used to fail the test execution if there is no events. I don't know if this test will give false positives, though.

executeTests in Test := {
  val result = (executeTests in Test).value
  if (result.events.isEmpty) {
    (streams.value.log.error("No test events found"))
    result.copy(overall = TestResult.Error)
  }
  else result
}

retronym added a commit to retronym/scala that referenced this issue Aug 31, 2016
Discussion: sbt/sbt#2722

This commit checks that some test events exist in the
test log for `test/it:test` before trusting the result
of `Success`.
retronym added a commit to retronym/scala that referenced this issue Aug 31, 2016
Discussion: sbt/sbt#2722

This commit checks that some test events exist in the
test log for `test/it:test` before trusting the result
of `Success`.
eed3si9n added a commit to eed3si9n/sbt that referenced this issue Aug 31, 2016
@eed3si9n eed3si9n self-assigned this Aug 31, 2016
eed3si9n added a commit to eed3si9n/sbt that referenced this issue Aug 31, 2016
@eed3si9n
Copy link
Member

@retronym Thanks for the hint. Here's my fix - #2723

sbt-test-fork-swallows-error> test
[error] Uncaught exception when running tests: java.lang.Throwable
[trace] Stack trace suppressed: run last test:test for the full output.
[error] Error: Total 0, Failed 0, Errors 0, Passed 0
[error] Error during tests:
[error]         Forked test harness failed: null
[error] (test:test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 1 s, completed Aug 31, 2016 4:18:57 AM

@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 dwijnand added this to the 0.13.13 milestone 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
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
@eed3si9n eed3si9n self-assigned this Jan 15, 2017
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

3 participants