Testng test hangs and never exits

In an attempt to migrate from a system of ant build scripts to Gradle, I have a build script set to create many dynamic tasks for our suites. When I attempt to run any testNG suites I am getting an unexpected exception thrown from Gradle. Stacktrace is below. This error is happening pretty consistently unless I crank up the memory of the test task. I can get it to happen less frequently, but not eliminate it.

I have been able to narrow down when this happens. Whenever my tests do a testNG hard assert (org.testng.Assert.assert___()) which fails OR I have an uncaught exception (that was being used to trigger test failure) that bubbles up through the test. It will output the below stacktrace and then when all tests finish executing the command line just sits there. This is also causing our jenkins server to hang and preventing us from going forward with our gradle migration.

It looks like this might be a memory issue. When I ramp up the memory I can reduce the frequency of this issue, but it will still happen occasionally. Any advice is much appreciated.

I’m on gradle 2.1, but rolling back to 1.9 seems to eliminate the issue. I don’t even have to give it additional memory and I still never have the error. 1.9 seems to lose some valuable testNG reporting functionality though. It would be great if this worked in 2.1

task "dynamic_${suite}_${lang.key}_${brow}_${env}"(type:Test){
       dependsOn jarTests
       ignoreFailures = true
       classpath = sourceSets.myTests.runtimeClasspath
       testClassesDir file("build/tests/classes/test/suites/${suite}/")
       includes = ["${suiteFirstLetterCap}Suite.class", 'BEC*.class']
       useTestNG {
         outputDirectory = file("build/reports/tests/suites/${suite}-${lang.key}-${brow}-${env}")
        }
       options.suites(new File("build-scripts/testng/${suite}/${env}/testng-${suite}-${env}-${langFirstLetterCap}-${browserFirstLetterCap}.xml"))
       options.useDefaultListeners(true)
       doLast{
        println "finished running suite"
       }
         afterTest { desc ->
         println "ending test ${desc}"
       }
      }
[system.err] 11:50:50.712 [ERROR] [org.gradle.messaging.remote.internal.hub.MessageHubBackedObjectConnection] Unexpected exception thrown.
11:50:50.713 [ERROR] [system.err] org.gradle.messaging.remote.internal.MessageIOException: Could not write message [ChannelMessage channel: org.gradle.api.internal.tasks.testing.TestResultProcessor, payload: [MethodInvocation method: output()]] to '/0:0:0:0:0:0:0:1:62709'.
11:50:50.713 [ERROR] [system.err]
at org.gradle.messaging.remote.internal.inet.SocketConnection.dispatch(SocketConnection.java:115)
11:50:50.713 [ERROR] [system.err]
at org.gradle.messaging.remote.internal.hub.MessageHub$ConnectionDispatch.run(MessageHub.java:279)
11:50:50.713 [ERROR] [system.err]
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
11:50:50.713 [ERROR] [system.err]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
11:50:50.713 [ERROR] [system.err]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
11:50:50.713 [ERROR] [system.err]
at java.lang.Thread.run(Thread.java:695)
11:50:50.714 [ERROR] [system.err] Caused by: java.lang.NullPointerException
11:50:50.714 [ERROR] [system.err]
at org.gradle.messaging.serialize.DefaultSerializerRegistry$TaggedTypeSerializer.write(DefaultSerializerRegistry.java:76)
11:50:50.714 [ERROR] [system.err]
at org.gradle.api.internal.tasks.testing.worker.TestEventSerializer$2.write(TestEventSerializer.java:64)
11:50:50.714 [ERROR] [system.err]
at org.gradle.api.internal.tasks.testing.worker.TestEventSerializer$2.write(TestEventSerializer.java:60)
11:50:50.714 [ERROR] [system.err]
at org.gradle.messaging.remote.internal.hub.MethodInvocationSerializer$MethodInvocationWriter.writeArguments(MethodInvocationSerializer.java:67)
11:50:50.715 [ERROR] [system.err]
at org.gradle.messaging.remote.internal.hub.MethodInvocationSerializer$MethodInvocationWriter.write(MethodInvocationSerializer.java:63)
11:50:50.715 [ERROR] [system.err]
at org.gradle.messaging.remote.internal.hub.MethodInvocationSerializer$MethodInvocationWriter.write(MethodInvocationSerializer.java:48)
11:50:50.715 [ERROR] [system.err]
at org.gradle.messaging.serialize.kryo.TypeSafeSerializer$2.write(TypeSafeSerializer.java:46)
11:50:50.715 [ERROR] [system.err]
at org.gradle.messaging.remote.internal.hub.InterHubMessageSerializer$MessageWriter.write(InterHubMessageSerializer.java:108)
11:50:50.715 [ERROR] [system.err]
at org.gradle.messaging.remote.internal.hub.InterHubMessageSerializer$MessageWriter.write(InterHubMessageSerializer.java:93)
11:50:50.715 [ERROR] [system.err]
at org.gradle.messaging.remote.internal.inet.SocketConnection.dispatch(SocketConnection.java:112)
11:50:50.716 [ERROR] [system.err]
... 5 more

We see the same issue in gradle 1.12 - looks like it is fixed in 2.3: GRADLE-3190

So my question is… GRADLE-3190 was reported on 2.1, and we see it in 1.12. It appears that it was not present in 1.9.

Is it obvious from commit history when the bug was introduced? We could wind back to 1.9, 1.10 or 1.11 to avoid this intermittent problem.

Otherwise, there does not yet seem to be 2.3-rc1 available and I’m reluctant to switch our production CI to 2.4 nightly.

You can download the latest 2.3 build here. I anticipate an RC should be out very soon and the final release shortly after.

Thanks - I’ll give that a go. I can probably argue for 2.3-rc1 usage here.