Capturing test output from multiple threads

I’m building what I think is fairly standard java code using the java plugin, using the test task to execute junit tests. Whether I set testLogging.showStandardStreams to false, or don’t set it (i.e. leave the default value) I see standard out from a test in the output of ./gradlew build…when that output comes from a thread that’s not the main thread. No output from the main thread appears.

I’ve seen this using gradle versions 2.8 and 2.10:
:server:test <output from a non-main thread> :server:check

The output is complete. What I mean is that it appears the check task knows to wait for all threads to complete before continuing.

If it’s helpful, the output is coming from a thread registered with https://docs.oracle.com/javase/8/docs/api/java/lang/Runtime.html#addShutdownHook-java.lang.Thread-

-DB

I can’t quite follow your explanation.

Are you saying that the output from the shutdown hook is not displayed? Or that, when you add a shutdown hook you only see its output?

Sorry it wasn’t clear.

I’m saying that the output from the shutdown hook is displayed, and I don’t expect it to see it. I don’t see any other output besides what the shutdown hook generates. When there’s no shutdown hook, I don’t see any output (as expected), though there’s plenty of code in the main thread generating output.

-DB

Thanks for the clarification.

This is actually working as “intended”. Gradle captures the output during tests, and associates it with the test case. Within a shutdown hook, there’s no test case to associate it with and nowhere else to send it other than to “the console”. This is the safest default as that output might be useful information, and there’s no other way to capture it.

It is conceivable that there could be an option on the Test task type to suppress any non test output from the test process.

That makes sense, though it does seem like at least a mention of this would help near https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.logging.TestLoggingContainer.html#org.gradle.api.tasks.testing.logging.TestLoggingContainer:showStandardStreams. https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/logging/TestLogEvent.html#STANDARD_OUT does say “A test has written a message…” so I suppose it’s technically correct as is, but it’s also surprising to see output when showStandardStreams is false.

If there is some way to capture this output, I think that would be even better. I suppose suppressing it would also be better than the current state, but it feels like there’s gotta be a way to capture it somehow.

-DB

And now that I’m staring at this longer, I see something slightly different than I wrote before, or perhaps I’m writing about a slightly different issue.

Using code with no shutdown hooks, everything is working as expected (i.e. no output to the console) with gradle 2.8. Gradle has captured test output in a thread named “Test worker”. Using both gradle 2.9 and gradle 2.10, gradle doesn’t capture the output…or at least it appears on the console in a thread named “Thread-6”.

Any idea what changed here, or what I can do differently to get gradle 2.9/2.10 to capture this output?

Thanks.

-DB

We changed some code around logging in Gradle 2.9. That might have caused a side-effect. It would be great if you could provide us with a small, reproducible example project.